0

我正在尝试制作一个 Like 搜索引擎,这对我的网站来说很简单。这是我正在使用的代码:

  $sql = mysql_query("SELECT * FROM books WHERE tags LIKE '%$_GET[term]%' LIMIT 0,$_GET
  [results]");

while($ser = mysql_fetch_array($sql)) {
    echo $ser['title']."<br />";


}

但是当它搜索时,它只会在我的标签中寻找一个词。有人对如何让它搜索我的所有标签有任何好主意吗?

4

3 回答 3

0

i highly recommend not to use value directly from user first parse it, to protect yourself from SQL injections

try removing the limit and then check is it give same result?

于 2013-05-29T17:45:11.267 回答
0

Use this:-

$keywords =$_GET[term];
$keywords = explode('delimiter', $keyword);
$searchTermKeywords = array();
foreach ($keywords as $word) 
{

$searchTermKeywords[] = "tags LIKE '%$word%'";

}

$result= mysql_query("SELECT * FROM books WHERE ".implode(' AND ', $searchTermKeywords).");
于 2013-05-29T17:46:15.313 回答
0
$sql = mysql_query("SELECT * FROM books WHERE tags LIKE '%$_GET[term]%'");

从查询中删除限制,您应该从查询中获取所有匹配的行。

于 2013-05-29T17:41:22.333 回答