JQuery PHP Tutorials

Jquery Autocomplete With PHP and Mysql Example


Below is the small example of Jquery autocomplete using PHP and Mysql.





search.php

$term = trim(strip_tags($_REQUEST['term']));

$query = "SELECT id, name from employees WHERE first_name LIKE '%$term%'";
$return_arr = array();
$result = mysql_query($query,$db);

while($row = mysql_fetch_array($result)) {
$return_arr[] = array("value"=>$row['id'],"label"=>$row['name']);
}
echo $jsonResponse = json_encode($return_arr);
flush();
?>

For local data with out mysql autocomplete