FIND_IN_SET 在 cakephp 中不工作

FIND_IN_SET in cakephp not working

我有一个 table,其中类别 ID 作为逗号分隔值存储在数据库中,因此我需要在此逗号分隔值中搜索另一个数组。

需要在Posts.category_ids

中搜索$required_ids_array
$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)')
        );
    }

提前致谢

这个解决方案对我有用 :)

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

您应该在 WHERE 条件数组中写入您的 FIND_IN_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');