0

On my search result page, I wanted to search for "Nintendo DS Lite - Pink"

I used following code:

Ex:

$search_text = "Nintendo DS Lite Pink";

$kt=split(" ",$search_text);//Breaking the string to array of words

// Now let us generate the sql 
while(list($key,$val)=each($kt))
{
	if($val<>" " and strlen($val) > 0)
	{
		$q .= " name like '%$val%' or ";
	}
}// end of while

//Remove the last 'OR'
$q=substr($q,0,(strlen($q)-3));

Than the $q would be:

SELECT * FROM `products`
WHERE  
name like '%Nintendo%' or  
name like '%DS%' or  
name like '%Lite%' or  
name like '%Pink%'

And i am getting Mysql Output given below:


1) Activity Meter - DS.
2) Nintendo DS Red.
3) Nintendo DS Lite Pink.
4) Nintendo DS Lite Turquoise.

But the third result is most accurate/relevant then first two result.

Please help me out to get the most accurate row first then the relevant rows as per their relevancy with search term "$search_text"

Many Thanks in Advance.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by almostbob
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.