php - 如何使用 %% 搜索通过包含多个值的数组查找字段

标签 php cakephp find

我正在尝试通过 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/

相关文章:

php - SQL Order By - 最后显示某些记录

php - 使用 php 获取用户 ip 地址的最可靠方法?

php - CakePHP 从 URL 中删除索引操作

CakePHP 3.x - View 中的 AuthComponent::user()

php - Symfony 3 登录后重定向到 http 而不是 https

javascript - PDFbox 可以在 html、php 和 javascript 中使用吗?

mysql - CakePHP 3 - 查找器未加载正确的数据

excel - 使用 Right()、Len() 和 Find() 输出公式时出现 VLOOKUP 错误

linux - 在 Linux 中快速查找文件名并指定目录的方法

linux - 使用排除列表在 bash 中查找目录