Hi
I'm an editor at Wrox. I'm only just getting into PHP, but have some experience with ASP and I think I understand what you're doing here.
I think you want a script that will take a search string like "blue trousers" and turn it into "keywords like blue or keywords like trousers", yes? (Trousers being English English for pants, of course)
At the moment, you loop through each word in the search string. If the current word is AND, NOT, or OR, you react one way -- you add a whole new condition to the SQL WHERE clause. If it's just a regular word, you react another way -- you just append that word to the existing SQL WHERE clause.
What you need to do is this. If two regular words appear side by side, without NOT, AND, or OR between them, you need to add OR for yourself. The easiest way to find out if two 'regular' words appear together is to use a flag. I'm afraid I must resort to pseudocode here -- I hope it's clear enough.
if (currentWord is AND, NOT, or OR) {
// do what you do anyway
// then set this to show that we've just had a keyword
// this will be useful in a second
$lastWordWasKeyWord = true;
} else {
// this is just a regular word -- not AND, NOT, or OR
if ($lastWordWasKeyWord) {
// do what you do anyway -- just add this word to the
// SQL String
} else {
$strWhere = $StrWhere." or keywords like ".$arrSearch[$i]." ";
}
$lastWordWasKeyWord = false
}
That way, if I type in "clean underwear", $strWhere should end up as "keywords like clean or keywords like underwear"
I hope this makes sense... if not, maybe somebody who knows more PHP will help make it clearer! I promise I am learning though!
Cheers
Dave