FullText仅搜索显示1个结果

时间:2012-06-24 01:20:35

标签: php mysql sql full-text-search

我正在输出搜索查询的结果,但由于某种原因,它不会输出多个结果。 可能是因为我累了,但是有人发现了我正在制造的错误吗?

我想要它做的是,用搜索栏中输入的单词搜索我的数据库,找到所有匹配或输入的匹配。

我错过了什么吗?

$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;

先谢谢。

1 个答案:

答案 0 :(得分:0)

如果您要搜索包含单词test的任何内容,则应使用*作为通配符

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

此外,'部分的Against撇号似乎已关闭。