开发者

How do I search titles in mysql?

开发者 https://www.devze.com 2023-02-18 14:32 出处:网络
I am using LIKE operator for searching the title. But it not giving desired result when the user types word with spaces, what can be done?

I am using LIKE operator for searching the title. But it not giving desired result when the user types word with spaces, what can be done?

Example: 开发者_如何学Pythontitle has - national foundation

When I type national, it returns this title but when national geography, it shows no result found. How to remove this space or how to search properly when user types with spaces?


SELECT Title FROM table
WHERE MATCH (title)
AGAINST ('national geography');


assuming the search query the user inputs is stored in $search

$ex=explode(' ',$search);
$tempq='';
foreach ($ex as $s){
    $tempq.=" or title sounds like '$s' ";
}
$tempq=substr($tempq,4);
$results=mysql_query("select * from TABLE where $tempq");

for better and faster results remove the 'sounds' , index your column , limit search queries .

'sound like' will return results that sounds together ex : may return "like" if user searched for "layk" ... i hope this helps .

0

精彩评论

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