1

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"/>
1
  • Your PHP code has syntax error. Rest looks OK. Commented Apr 6, 2014 at 11:01

2 Answers 2

1

I think source needs to be a function which does the ajax request and returns the results.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Thanks, this managed to get the job done! Next time I will pay more attention to the syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.