If you were to put the detail here into a console, it would probably fail:
$query = "SELECT * FROM mytablename WHERE";

foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%each%' ";
else
$query .= "OR keyword LIKE '%each%' ";
as the result would show "...WHEREkeywords .." and "WHEREOR ..."

You need to put a space after the WHERE inside the double quotes: $query = "SELECT * FROM mytablename WHERE ";

Acorn