php - How to find fields by an array which contains multiple values by using like %% search -
i trying multiple fields match ids(1, 2, 3) %% search. have tried make work 2 hours, hasn't worked though looks pretty simple.
$ids = array ('1','2','3'); $result = $this -> model -> find ('all', array( 'conditions' => array( 'model.category like' => '%'.$ids.'%') ));
i need somebody's help.
i'd suggest build 'conditions' array separately. example:
$ids = array ('1','2','3'); $conditions = array(); foreach($ids $id){ $conditions['or'][] = array( 'model.category like' => '%'.$id.'%') } $result = $this->model->find('all', array('conditions'=>$conditions));
Comments
Post a Comment