开发者

How can I restrict the SELECT MATCH AGAINST to return ony results that contains all searched terms?

If I my term is for example iphone ipod the following query

SELECT id FROM products WHERE MATCH (name) AGAINST ('$term')

will give me results that contai开发者_如何转开发n both terms or only one of them.

How can I restrict to show me only results that contain both terms? Speed is my concern.

Thank you.


Add a + before every word:

$words = explode(" ", $term);
$all = implode(" +",$words);

$sql = 
   "SELECT id 
    FROM products
    WHERE MATCH (name) AGAINST ('+" . $all . "' IN BOOLEAN MODE)"

Documentation

Be sure to escape the input terms to prevent SQL Injection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜