You have to put every keyword in its own “like” statement:
public function getAll($keywords = NULL) {
$sql = 'SELECT * FROM nes';
if ($keywords) {
$sql .= 'WHERE keywords LIKE "%'.
implode('%" AND keywords LIKE "%', $keywords).'%"';
}
/* process the SQL query here */
}
Note that the keywords aren’t being sanitized in the above code. However you decide to do it, the principle stays the same: put each keyword in its own “like” section.
It looks like you have your own class that you’re using, so it’s hard to say for certain, but once you have the SQL string built (and remember, my version doesn’t sanitize input), then you should just be able to leave everything else the same. Execute the query, get the results, etc.
As long as your mysql table is not Innodb you can create a FULLTEXT search : [google]mysql search fulltext[/google].
This can be very useful if you want to rank results by the proximity of the words “internet” and “problem”.
There are a few gotchas:
Make sure you test with words longer than 3 chars (unless you change a setting).
Make sure you have plenty of test data in your table. Any resultset returning more than 50% of the total rows in your table is deemed to be a failed search…
I had some success by switching between keyword searches (using LIKE) and FULLTEXT searches, depending on the size of the words in a phrase.