简体   繁体   English

自动完成PHP,SQL和Javascript

[英]Auto-Complete PHP, SQL & Javascript

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: 这是我的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): 这是我的php(我已经删除了数据库的用户名和密码详细信息):

$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: 最后,这是我的html:

  <input id="search_term" name="search_term" type="text" placeholder="enter here..."/>
   <input id="submit" name="submit" type="submit"/>

我认为source需要是执行ajax请求并返回结果的函数。

The PHP code is wrong. PHP代码错误。 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. 该代码应该对其进行修复,以返回正确的json数据。 You missed the "," between the label and value. 您错过了标签和值之间的“,”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM