Web Hosting Talk







View Full Version : search script to search in certian way (help plz)


dazz
01-28-2003, 12:26 AM
I've made a search script which searches my mysql datatabase for URLs and there info.

but I'm having some problems, let's say somone searches for snoop dogg (the rapper)

they only return results with snoop in them

i need to know if there is a special way to make it so if somone searches for snoop dogg

they will get back results with snoop.dogg or snoopdogg or just snoop dogg in them

thanks u

iamdave
01-28-2003, 02:21 AM
Are you using PHP?

dazz
01-28-2003, 06:18 PM
yes :D

DeX
01-29-2003, 03:04 PM
Hi, take a look, it matches all the urls with words of query in it:
so it will match www.snoop-dogg.com as well as www.dogg-snoop.com

Hope you can go from this :


$queryString = "snoop dogg";
$queryArray = explode(' ',strtoupper(trim($query)));
if (count($queryArray)>0)
{
$q = "SELECT url FROM urls WHERE ";
for ($i=0;$i<count($queryArray);$i++)
{
if ($i) $q.=' AND ';
$q.="LOCATE('".$queryArray[$i]."',url) > 0";
}

$r=mysql_query($q);
// ....get the results by mysql_fetch_* functions
}


-DeX