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 .
精彩评论