Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用多个where向DB查询codeigniter_Codeigniter_Codeigniter 2 - Fatal编程技术网

使用多个where向DB查询codeigniter

使用多个where向DB查询codeigniter,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,当传递给sql查询的变量是如下数组时,我无法在中获取对DB的请求: $cl_phone = array(1,2,3); 以下型号代码 public function get_clients_enabled_array($cl_phones) { $this->db->order_by('filial_id'); $this->db->order_by('client_name'); $this->db->wh

当传递给sql查询的变量是如下数组时,我无法在中获取对DB的请求:

$cl_phone = array(1,2,3);
以下型号代码

public function get_clients_enabled_array($cl_phones) {

        $this->db->order_by('filial_id');
        $this->db->order_by('client_name');
        $this->db->where('status','1');

            foreach ($cl_phones as $value) {

                $this->db->where('client_id',$value);
            }

        $query = $this->db->get('clients');

        return $query->result_array();

}
查看显示空数组
array()


正确的方法是什么?

您需要在客户端id上使用
where\u in

假设你的$cl_手机只包含电话号码,你可以这样做

$this->db->order_by('filial_id');
$this->db->order_by('client_name');
$this->db->where('status','1');

$this->db->where_in('client_id', $cl_phones); // Change here

$query = $this->db->get('clients');
return $query->result_array();

此外,我相信您打算在
客户电话
上使用
where_in
,而不是在
client_id
(除非它们相同)

您确定
client_id
列同时等于1、2和3吗?我想你不需要
IN()
clause@MKhalidJunaid它起作用了!我认为where_in()必须与
JOIN
一起使用,这就是为什么我询问并猜测
in()
子句中需要的值(1,2,3),而不是发生这种情况的循环,因为我不知道
SELECT。。。IN()语句。参见
https://dev.mysql.com/doc/refman/5.6/en/select.html