jqueryUI使用php / mysql进行多次自动完成

时间:2014-03-05 18:25:42

标签: php jquery mysql jquery-ui autocomplete

我试过搜索,但我找到的结果都没有一个有效的答案,所以我希望也许有人可能会有一个建议(也许那些与我有同样问题的人找到了解决方案并且可以分享)

我一直在向我们求http://jqueryui.com/autocomplete/#multiple-remote 但是,我没有使用硬编码的潜在结果文本数组,而是想从mysql表中搜索该术语。

我的问题是搜索结果代码不起作用,而是抛出一个错误 PHP Parse错误:语法错误,意外')'

我的代码是     

sleep( 3 );
// no term passed - just exit early with no response
if (empty($_GET['term'])) exit ;
$q = strtolower($_GET["term"]);
// remove slashes if they were magically added
if (get_magic_quotes_gpc()) $q = stripslashes($q);

$items = array(
 $sql = mysqli_query($dbc, "SELECT first_name, last_name, email_addr FROM user_profiles
                     WHERE last_name LIKE '$q%'");
 while($sqlrow = mysqli_fetch_array($sql))
 {
   extract($sqlrow);
   echo "'a $first_name $last_name'=>$email_addr',";
 }

);


$result = array();
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
    array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key)));
}
if (count($result) > 11)
    break;
}

// json_encode is available in PHP 5.2 and above, or you can install a PECL 
//module in earlier versions
echo json_encode($result);

?>

错误行是具有mysqli_query()的行,我认为它采用了)并将其用作数组的结束括号() 我不知道如何编辑上面的代码,以便当用户在文本框中键入值时,自动完成功能将起作用。我应该注意,这段代码可以让我在同一个输入框中有多个自动完成值

感谢

0 个答案:

没有答案