【发布时间】:2012-02-13 01:01:16
【问题描述】:
我们的搜索建议有问题。每次我们点击我们网站上的建议时,它都会在搜索查询前面放置一个空格,这会导致查询失败。
我们用于建议的代码是这样的:
$query = $db->query("SELECT DISTINCT productnaam FROM product WHERE merk LIKE '$queryString%' LIMIT 10");
if($query) {
// While there are results loop through them - fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo '<li onClick="fill(\''.$result->merk.' '.$result->productnaam.'\');">'
.$result->merk.' '.$result->productnaam.''.'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
【问题讨论】:
-
$queryString来自哪里? (显示代码)
标签: php mysql autosuggest