The SQL won't work like that. They'll always be this:
OR keyword ='
at the end, so it would be:
OR keyword =' order by site_id DESC
You should have an error check after the query and before the fetch. Also, you don't need a foreach loop. Example:
...
$ary = explode(' ',$query);
$search = "keyword LIKE '%" . implode("%' OR keyword LIKE '%", $ary) . "%'";
$sql = "SELECT * FROM splinks WHERE $search ORDER BY site_id DESC";
$res=mysql_query($sql) or die("sql: $sql <br>Error: " . mysql_error());
...
So, if $query contained "speed dating", then the above code would create the SQL looking like this:
SELECT * FROM splinks
WHERE keyword LIKE '%speed%' OR keyword LIKE '%dating%' ORDER BY site_id DESC
That SQL would find a match on all of these values in the keyword column in the table:
dating service
speed demon
Nice to see you're dating again
I got a speeding ticket
I love dating people
I drive at high speeds all the time
I hope that's what you want.
🙂