使用多个where向DB查询codeigniter
当传递给sql查询的变量是如下数组时,我无法在中获取对DB的请求:使用多个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
$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