我正在尝试制作即时搜索脚本。当我输入查询时,一切正常,但是当我使用空格(空格)时,所有结果都消失了。我肯定知道我正在寻找的是一个结果。即时搜索在使用空间时不显示结果
例如,我首先搜索:“goog”,结果出现“google images”,然后当我想进一步搜索并添加“google i”时,结果消失。谁能告诉我为什么?我使用PHP和jQuery脚本。
在此先感谢。下面是代码:
的HTML
<input type="text" name="q" id="searchq">
jQuery的
$('#searchq').keyup(function() {
var srch_trm = $(this).val();
$.post('instantsearch.php', {squery: srch_trm}, function(resultz) {
$('#insresults').html(resultz);
});
});
的PHP
if(isset($_POST['squery'])) {
$queryz = mysql_real_escape_string(htmlentities($_POST['squery']));
if(!empty($queryz)) {
$qurn = mysql_query("SELECT * FROM `news` WHERE `title` LIKE '%$queryz%' ORDER BY `id` ASC");
//Check if News were found and then display them.
if(mysql_num_rows($qurn) > 0) {
while ($srchrown = mysql_fetch_array($qurn)) {
echo $srchrown['title']."<br>";
}
}
得到任何代码来看待? –
你在查询数据库吗? – Dropzilla
很可能这是你的php/mysql的问题,但没有任何代码,我们所能做的只是猜测。 –