从PHP中的SQL数据库自动完成无法正常工作

时间:2014-04-28 12:46:28

标签: php jquery mysql sql autocomplete

我在PHP mysql中有一个代码,用于自动完成一个无效的文本框。请检查问题是什么以及为什么它不起作用。

<html> 
<head> 
    <title>test jquery autocomplete</title> 
    <script type="text/javascript" src="jquery/js/jquery-1.4.2.min.js"></script> 
    <script type="text/javascript" src="jquery/js/jquery-ui-1.8.2.custom.min.js"></script> 
    <script type="text/javascript"> 

        $(document).ready(function(){
            $('#name').autocomplete({source:'suggest_zip.php', minLength:2});
        });

    </script> 
    <link rel="stylesheet" href="jquery/css/smoothness/jquery-ui-1.8.2.custom.css" /> 
    <style type="text/css"><!--

            /* style the auto-complete response */
            li.ui-menu-item { font-size:12px !important; }

    --></style> 
</head> 

<body> 

<form onsubmit="return false;"> 
    Enter a NAME
    <input id="name" type="text" /> 
</form> 

</body> 
</html>

suggest_zip.php

   <?php
$mydb = new mysqli('localhost', 'root', '', 'db');
$q = '%'.$_GET['term'].'%';
$stmt = $mydb->prepare(" SELECT DISTINCT(BRAND) from xml where BRAND LIKE ? ");
echo $mydb->error;
$stmt->bind_param('s', $q);
$stmt->execute();


$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$json[]=array(
        'value'=> $row["BRAND"],
        'label'=>$row["BRAND"]
                         );
}
echo json_encode($json);

每当我输入内容时,它应该从表格中提供一些数据作为自动完成。但是它没有为此抛出任何东西。请帮我纠正代码。

0 个答案:

没有答案