jquery自动完成与全文mysql研究

时间:2015-10-24 14:21:07

标签: javascript php jquery mysql

我尝试使用jquery autocomplete和mysql查询和全文研究(自制dbb)安装地址搜索表单。但我的脚本不起作用...... 研究只是我的第一个字符,当我写完整个单词时不要循环。 对于这项研究:“街1” 萤火虫表示:“GET /research.php?query=S”

我的jQuery脚本:

$(document).ready(function(){
    $('#search-bano').autocomplete({
    serviceUrl: 'research.php',
    dataType: 'json',
    onSelect: function (suggestion) {
        console.log(suggestion);
    }
 });
});

我的HTML脚本:

<input type="text" id="search-bano" value="">

我的php脚本(research.php):

$term = strip_tags(substr($_GET['query'],0, 100));
$term = utf8_decode($term);
$term = mysql_escape_string($term); // Attack Prevention
if($term!="")
{

 $query = mysql_query("select * from bano where MATCH(street)  AGAINST ('$term*')");
 $suggestions = array();
 if (mysql_num_rows($query))
 {
    while($row = mysql_fetch_assoc($query))
    {
        $display=''.$row['street'].'';
        $suggestions[] = array(
        "value" => $display,    
        "idstreet" => $row['idstreet']

    )       
 }

 echo json_encode(array('suggestions' => $suggestions));
}

0 个答案:

没有答案