$sql = array('0'); // Stop errors when $words is empty
foreach($words as $word){
$sql[] = 'name LIKE %'.$word.'%'
}
$sql = 'SELECT * FROM users WHERE '.implode(" OR ", $sql);
Edycja:kod dla CakePHP:
foreach($words as $word){
$sql[] = array('Model.name LIKE' => '%'.$word.'%');
}
$this->Model->find('all', array(
'conditions' => array(
'OR' => $sql
)
));
Przeczytaj o tych rzeczach:http://book.cakephp .org/1.3/pl/widok/1030/Złożone-warunki-znajdowania