在cakephp中的\u集合中查找\u不工作

q5lcpyga  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(413)

我有一个表,其中类别ID作为逗号分隔值存储在db中,因此我需要在这个逗号分隔值中搜索另一个数组。
需要搜索吗 $required_ids_arrayPosts.category_ids ```
$required_ids_array = Array (
[0] => 14
[1] => 15
[2] => 16
[3] => 25
[4] => 35
);

if(isset($required_ids_array)){
foreach ($required_ids_array as $storeId) {
$condition = array ();
$condition ['AND'] ['Post.status']=1;
$blogs = $this->Post->find('all', array(
'conditions' => $condition,
'order' => 'Post.id.DESC',
'limit'=>'4',
'FIND_IN_SET(''.$storeId.'',Post.category_ids)')
);
}

提前谢谢
8tntrjer

8tntrjer1#

您应该在where条件数组中写入find\u in\u set条件。你在数组外写的。

$blogs = $this->Post->find('all', array 
 ('conditions' => array('Post.status' => 1, 'FIND_IN_SET(\''. $storeId 
   .'\',Post.category_ids)' )),'order' => 'Post.id 
   DESC','limit'=>'4');
1l5u6lss

1l5u6lss2#

此解决方案对我有效:)

$blogs = $this->Post->find ( 'all', array (
                                    'conditions' => array (
                                    'Post.status' => 1,
                                    'Post.id !=' => $id,
                                    'FIND_IN_SET(?, Post.category_ids)' => array ($storeId) ),
                            'limit' => 4,
                            'order' => 'Blog.modified DESC'  
                    ) );

相关问题