Hi there.....
Trying to write a query which will search several mysql-tables for several words...but it just won't work...HELP !
I start off with a simple search input field. Let's say we fill in the words; 'Robert goes nuts'.
I've got a databse with 4 table-cols ; id, name,details & keywords. I want him to display every row which contains all three words in total. So if the table looks like this;
id name details keywords
1 Robert gets sleepy
2 Goes Nuts Robert
3 Nuts Robert Lazy
4 Nuts Robert goes
it should find both 2 and 4.
- Here's what I came up with:
$split= explode (" ", $search);
$sql = "SELECT * FROM $table WHERE name LIKE '%$split[0]%' OR details LIKE '%$split[0]%' OR keywords LIKE '%$split[0]%'";
for ($k=1; $k<count($split); $k++){
$sql.=" AND name LIKE '%$split[$k]%' OR details LIKE '%$split[$k]%' OR keywords LIKE '%$split[$k]%'";
}
But it won't work.
Is there anyone who can edit just the query and get it working..?
...........help ?!