开发者

MYSQL Selecting EXACT word with MATCH query?

开发者 https://www.devze.com 2023-02-13 12:22 出处:网络
I\'m trying to select posts using MATCH to find strings that contain the exact word. Currently it selects strings that contains the word no matter what it looks like. I want it to select strings that

I'm trying to select posts using MATCH to find strings that contain the exact word. Currently it selects strings that contains the word no matter what it looks like. I want it to select strings that contains the exact value as defined. the sql code currently looks like this:

$searchstrin开发者_运维问答g = "#cat";
SELECT * FROM posts WHERE MATCH(content) AGAINST ('$searchstring' IN BOOLEAN MODE)

How do I get it to select the strings that contains the exact value that is defined?


You could switch over to using LIKE

$sql="SELECT * FROM `posts` WHERE `content` LIKE '%{$searchstring}%'"

That would find only posts with at least that search string in it.


$sql="SELECT * FROM `posts` WHERE `content` LIKE '%{$searchstring}%'"

But the above query will search and display all the results having $searchstring in it.

could use :

$sql="SELECT * FROM `posts` WHERE `content` LIKE '::{$searchstring}::'"
0

精彩评论

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