So im trying to populate an auto-complete search form from my database. Here is my php code that creates an array
$leaders= mysql_query("SELECT model_name,model_id FROM models
ORDER by model_name DESC");
while($leader=mysql_fetch_array($leaders)){
$model= $leader['model_name'];
$modelid= $leader['model_id'];
$name[] = array('label'=> $model, 'value'=> $modelid);
$count = $count + 1;
}
$fp = fopen('results.php', 'w');
fwrite($fp, json_encode($name));
fclose($fp);
My problem lies somewhere within the jquery auto complete, the search form just returns a huge list of all the products in my json without filtering when the user types. My ideal goal would be to assign the value to the end of a url. Ex. “http://www.example.com/” + value
$(function() {
$("#search").autocomplete({
source: function(request, response) {
$.ajax({
url: "results.php",
dataType: "json",
data: { q: request.term },
success: function(data) {
response($.map(data, function(value,key) {
return { label:value.label , value: value.value }
}));
}
});
},
minLength: 2
});
});
Thanks for the help
i think your query was worng. you must use like condition on your query
to fetch the particular selected result