Reputation: 27
I am trying to run this Auto-Complete code, but it doesn't seem to be working. Can anyone help?
Thanks in advance.
Here is my Javascript:
<script type="text/javascript">
$(document).ready(function(){
$("#search_term").autocomplete({
source:'search_lookup.php',
minLength:2
});
});
</script>
Here is my php (I have removed my Database username and password details):
$get_term= $_GET["term"];
$sql_statement = mysql_query("SELECT pi.name, pi.middle_name, ad1.address_name FROM person_info pi, address_1 ad1, WHERE pi.name LIKE '%$get_term%' OR pi.middle_name LIKE '%$get_term%' OR ad1.address_name LIKE '%$get_term%' ORDER BY pi.name");
$json=array();
while ($people= mysql_fetch_array($sql_statement)) {
$json[]=array(
'label'=>$people['pi.name'].''.$people['pi.middle_name'].''.$people['ad1.address_name'] 'value'=>$people['pi.name'].''.$people['pi.middle_name'].''.$people['ad1.address_name']
);
}
echo json_encode($json);
?>
Finally, here is my html:
<input id="search_term" name="search_term" type="text" placeholder="enter here..."/>
<input id="submit" name="submit" type="submit"/>
Upvotes: 1
Views: 645
Reputation: 536
The PHP code is wrong. If you have ran that yourself, you would see it gives a parse error.
$json[]=array('label'=>$people['pi.name'].''.$people['pi.middle_name'].''.$people['ad1.address_name'], 'value'=>$people['pi.name'].''.$people['pi.middle_name'].''.$people['ad1.address_name']);
That code should fix it, for returning the correct json data. You missed the "," between the label and value.
Upvotes: 0
Reputation: 530
I think source needs to be a function which does the ajax request and returns the results.
Upvotes: 1