I use the following code to seperate two words from a search, then make an sql query string to search the fields accordingly. It works great with one word, but when more than word is used, everything happens fine except the "AND" sections is never added. I just get "field1 like $word field1 like $word"
It nevers knows when to put the "and" conjunstion in there. Why?
$method = array(0=>" OR ", 1=>" AND ");
$words = split(" +",addslashes($searchwords));
$query = "select * from test where ";
$once=0;
foreach($words as $word){
if ($once) $query.=$method[$andor];
$query.= "field1 like '%$word%'";
$once=1;
}
print $query;