sql >> Database teknologi >  >> RDS >> Mysql

SQL LIKE % inde i array

$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);

Edit:kode til CakePHP:

foreach($words as $word){
    $sql[] = array('Model.name LIKE' => '%'.$word.'%');
}

$this->Model->find('all', array(
    'conditions' => array(
        'OR' => $sql
    )
));

Læs om disse ting:http://book.cakephp .org/1.3/en/view/1030/Complex-Find-Conditions



  1. VARCHAR vs TEXT i MySQL

  2. Sådan installeres phpMyAdmin på sin egen app

  3. Vælg mellem flere borde uden en joinforbindelse?

  4. Forespørg punkter inden for en given radius i MySQL