我已尝试过此代码的多种变体,但似乎都没有正常工作。我希望我的搜索在busname或busdba列中查找变量并返回结果。如果你键入一个正确的busname,当前的代码只返回,但不是busdba,这对我来说很奇怪。这是代码:
if(isset($_GET['term'])) {
$q = $_GET["term"];
if (!$q) return;
$return_arr = array();
$query = mysql_query("SELECT * FROM busclients WHERE busdba OR busname LIKE '$q%'")or die(mysql_error());
while ($result = mysql_fetch_array($query)) {
$busname = $result['busname'] . ", " . $result['busdba'];
if(isset($busname)){
$description['id'] = 'viewbusiness.php?id=' . $result['ID'];
$description['value'] = $busname ;
array_push($return_arr,$description);
}
}
echo json_encode($return_arr);
}
答案 0 :(得分:0)
您的查询错误。请更正
"SELECT * FROM busclients WHERE busdba LIKE '$q%' OR busname LIKE '$q%'"