<?php
/*====================== Database Connection Code Start Here ======================= */

define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "vosmcyqy_af"); // set database user
define ("DB_PASS","2@RhUH7JY78@@@9823@KLULasd"); // set database password
define ("DB_NAME","vosmcyqy_afri"); // set database name

$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME) or die("Couldn't make connection.");
//$db = mysqli_select_db(DB_NAME, $link) or die("Couldn't select database");
/*====================== 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_cc.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;
?>