Database search

I have the following

$find = strtoupper($search); 
$find = strip_tags($search); 
$find = trim ($search); 

$searchstring .= "upper(column1) LIKE '%$find%' || upper(column2) LIKE '%$find%' || upper(column3) LIKE '%$find%'"; 

$data = mysql_query("SELECT * FROM table WHERE $searchstring") or die(mysql_error()); 

when i type in a one word query it finds all entrys for that word, ie. php and it will find php

when i type more than one word thats when things go wrong, ie. php help it return no results found.

I have tried MATCH… AGAINST but its still the same.

Does anyone have any suggestions

I’ve come up with this

[code]$find = strtoupper($search);
$find = strip_tags($search);
$find = trim ($search);
$split = (str_word_count("$find",1));

foreach($split as $string) {
$string = $string;
}
$searchstring .= “upper(description) LIKE ‘%$string%’ || upper(title) LIKE ‘%$string%’ || upper(url) LIKE ‘%$string%’”;

$data = mysql_query(“SELECT * FROM asLinks WHERE $searchstring”) or die(mysql_error()); [/code]

Can someone have a look at it and see if it looks ok, it works fine but I just want a second opinion

If you use multiple search words in an ‘ANY’ type of way, you could unravel them:

[code]$allwords = explode(" ", $searchquery);

$whereclause = “”;
for ($i = 0; $i < count($allwords); $i++) {
if ($i > 0) { $whereclause .= " || “; }
$whereclause .= " mycolumn like '”.$allwords[$i]."’";
}

$sql = “SELECT * FROM asLinks”.$whereclause;[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service