我正在尝试通过 Like %% 搜索获取与这些 ids(1, 2, 3) 匹配的多个字段。 我尝试了两个小时,但没有成功,尽管看起来很简单。
$ids = array ('1','2','3');
$result = $this -> Model -> find ('all', array(
'conditions' => array( 'Model.category LIKE' => '%'.$ids.'%')
));
我需要有人的帮助。
最佳答案
我建议您单独构建“条件”数组。例如:
$ids = array ('1','2','3');
$conditions = array();
foreach($ids as $id){
$conditions['OR'][] = array( 'Model.category LIKE' => '%'.$id.'%')
}
$result = $this->Model->find('all', array('conditions'=>$conditions));
关于php - 如何使用 %% 搜索通过包含多个值的数组查找字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506182/