<?php
/*====================== Database Connection Code Start Here ======================= */
// $dbc=mysqli_connect("localhost","gurudumu_rad3","@@rad#@@@2023!!","gurudumu_dar");
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "u486354202_kgit"); // set database user
define ("DB_PASS", "GH@@Y98it%9a#@!*&&"); // set database password
define ("DB_NAME", "u486354202_kone"); // set database name
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME) or die("Couldn't make connection.");
//$dbc=mysqli_connect("localhost","u486354202_kgit","GH@@Y98it%9a#@!*&&","u486354202_kone");
// $dbc=mysqli_connect("localhost", "mulberr3_qen", "@@@5342@@qne#&!#","mulberr3_spm");
/*====================== Database Connection Code End Here ========================== */

// Here, we will get user input data and trim it, if any space in that user input data
$user_input = trim($_REQUEST['term']);

// Define two array, one is to store output data and other is for display
$display_json = array();
$json_arr = array();
 

$user_input = preg_replace('/\s+/', ' ', $user_input);

$query = 'SELECT p_name, product_id as id FROM products  WHERE p_name LIKE "%'.$user_input.'%" order by p_name limit 50';
 
$recSql = mysqli_query($link,($query));
if(mysqli_num_rows($recSql)>0){
while($recResult = mysqli_fetch_assoc($recSql)) {
  $json_arr["id"] = "name_c.php?id=".$recResult['id'];
  $json_arr["value"] = $recResult['p_name'];
  $json_arr["label"] = $recResult['p_name'];
  array_push($display_json, $json_arr);
}
} else {
  $json_arr["id"] = "#";
  $json_arr["value"] = "";
  $json_arr["label"] = "No Result Found !";
  array_push($display_json, $json_arr);
}
 
	
$jsonWrite = json_encode($display_json); //encode that search data
print $jsonWrite;
?>