문제

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"/>
도움이 되었습니까?

해결책 2

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top