2012-06-24 115 views
-1

我正在输出搜索查询的结果,但由于某种原因,它不会输出多个结果。 可能是因为我很累,但是有人发现我正在犯的错误?全文搜索仅显示1结果

我希望它能做的就是用搜索栏中的输入词搜索我的数据库,并查找输入的所有匹配或近似匹配。

我错过了什么?

$search = $_POST['search']; 

// We preform a bit of filtering 

$filtered = mysql_real_escape_string($search); 

//Select what add to look for. 
$ad_type = $_POST['']; 

//Now we search for our search term, in the field the user specified 
$sql = "SELECT * FROM busadverts WHERE MATCH(advert_name, advert_description, advert_tags) AGAINST('". $filtered ." IN BOOLEAN MODE')"; 

$result = mysql_Query($sql) or die(mysql_error()); 
//And we display the results 

while($row = mysql_fetch_array($result)) 
{ 

$adname = $row['advert_name']; 
$adimage = $row['advert_image']; 
$addesc = $row['advert_description']; 
$adurl = $row['advert_url']; 

$searchresult .= "<div style='width: 800px; height: 200px;'> 
<div class='titleBar' style='text-align: center; background: #000; color: #fff;'>" 
. $adname . " 
</div> 
<div class='advertimage' style='width: 150px; height: 150px; float: left; background: #111;text-align: center;'> 
<img src='" . $adimage . "' /> 
</div> 
<div class='advertdescription' style='width: 635px; height: 150px; float: left; background: #222;color: #fff; padding-left: 15px;'>Description: <br />" 
. $addesc ." 
<br /><br /> Website link: <a href='" .$adurl."'>" 
. $adurl . "</a> 
</div> 

</div>"; 

} 

//This counts the number or results - and if there wasn't any it gives them a little message explaining that 
$anymatches=mysql_num_rows($result); 
if ($anymatches == 0) 
{ 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
} 



    mysql_free_result($result); 

//And we remind them what they searched for 
echo "<b>Results: </b> " .$search. "" ; 
echo $searchresult; 

在此先感谢。

+0

也注意到,它并没有拉出所有东西,例如“测试”似乎拉动测试或测试或测试,但如果我将“测试”作为搜索词,它只会显示大写字母的项目,因为这样会最好只加入所有搜索? –

+0

我找不到任何错误 - 你确定有多个匹配的行吗?你在哪里发起'$ searchresult'?也许你需要在while循环之外做到这一点? –

+0

我有两行包含Swindon,在其描述或标题中,一个说“Swindon”,另一个说“swindon”,但只有一个会显示。 –

回答

0

如果你要搜索反对任何包含test你应该使用*作为通配符

$sql = "SELECT * FROM busadverts WHERE MATCH(advert_name, advert_description, advert_tags) AGAINST('*". $filtered ."*' IN BOOLEAN MODE)"; 

而且这个词,它看起来像你的'撇号在Against部分是关闭的。