dongyi9298
2018-08-10 05:09
浏览 238
已采纳

cakephp中的FIND_IN_SET不起作用

I have a table in which category ids are stored in the DB as comma separated values, so I need to search another array in this comma separated values.

Need to search $required_ids_array in Posts.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)')
        );
    }

Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我有一个表,其中类别ID以逗号分隔的值存储在数据库中,所以我需要搜索另一个 此逗号分隔值中的数组。

需要在中搜索 $ required_ids_array Posts.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', '限制'=>'4', 'FIND_IN_SET(\''。$ storeId。'\',Post.category_ids)') ); \ n}

提前致谢

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanqian6982 2018-08-10 07:02
    已采纳

    This solution worked for me :)

    $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'  
                        ) );
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题