像功能结果错误

I have written a code where the users searches in a webpage. here is the sample code where it is going wrong.

$first = true;

foreach ($terms as $each) 
{
    if ($first) {
        $query .= "keywords LIKE '%$each%' ";
        $first = false;
    }
    else {
        $query .= "OR keywords LIKE '%$each%' ";
    }

}

Here is an example where it fails: When the user enters "best o" then it should display the words which contains "%Best% %o%" in a single word but it is going to display all the results which contains 2 words as there is a space entered by the user in between best and o.

It's not searching them in a single word. It's searching "best" once and "o" once in all the words.