Php 组合where-like-where_in

Php 组合where-like-where_in,php,codeigniter,where,sql-like,where-in,Php,Codeigniter,Where,Sql Like,Where In,假设我在CI中有一个模型返回用户需要的内容 $find = 'something'; $id_user = Array ( [0] => 1 [1] => 5 [2] => 20 [3] => 21 ) ; 所以,我必须把它放在这里,但出了点问题 public function find_pr_by_user ($find,$id_users) { $this -> db -> where_in ('req_by_id'.$id_us

假设我在CI中有一个模型返回用户需要的内容

$find = 'something';
$id_user = Array ( [0] => 1 [1] => 5 [2] => 20 [3] => 21 ) ;
所以,我必须把它放在这里,但出了点问题

    public function find_pr_by_user ($find,$id_users) {
        $this -> db -> where_in ('req_by_id'.$id_users || 'check_by_id',$id_users || 'approve_by_id',$id_users);
        $this -> db -> where ("(ref_no LIKE '%$find%' || pr_title LIKE '%$find%' || req_date LIKE '%$find%')");
        $query = $this -> db -> get ('pr_data') ;
        return $query -> result () ;
    }
我得到错误数组到字符串的转换;我的输入来自
$find
$id\u用户
,可以是任何内容。我期望这个逻辑,给我表
PR\u DATA
中的所有数组,它在
ref\u no
PR\u title
req\u date
列上有
$id\u用户
*(1或5或20或21)但在
req\u by\u id
列中只有
按id检查\u
按id批准\u


有人能帮忙吗?

这个答案假设您的代码中的第一个
where_in()
中需要括号

不幸的是,CodeIgniter不完全支持带有活动记录的括号。因此,您必须使用
where()
,其中包含更复杂的SQL语法

public function find_pr_by_user ($find,$id_users) {
    $id_users_glued = implode(",",$id_users);
    $this->db->where('(req_by_id IN (' . $id_users_glued . ') || check_by_id IN (' . $id_users_glued . ') || approve_by_id IN (' . $id_users_glued . '))');
    $this->db->where("(ref_no LIKE '%$find%' || pr_title LIKE '%$find%' || req_date LIKE '%$find%')");
    $query = $this->db->get('pr_data') ;
    return $query->result () ;
}
在CI的活动记录中,语法的处理方式如下:

第一个WHERE将被视为:
WHERE(请求由id输入($id用户粘贴)|检查由id输入($id用户粘贴)|批准由id输入($id用户粘贴)

粘贴的
$id\u用户
将生成类似
1,2,3,4,5的内容

第二个,其中将被视为:
和(参考号类似“%$find%”| | pr|标题类似“%$find%”| |请求日期类似“%$find%”)


注意:我没有测试代码,因为我没有你的db结构。如果它不工作,请告诉我。

你收到了什么错误消息?请澄清你的输入和预期输出是的,很遗憾你不能那样使用
where\u in()
。你的参数适用于
where()
,但不适用于
where\u in()
。你必须使用一种变通方法来实现这一点。请参阅我的答案谢谢你,老兄……我的2x24小时在10分钟内就修好了……#很乐意帮忙。我以前也遇到过这个问题:)