codeigniter查询到具有多个位置的DB

时间:2014-04-21 12:32:32

标签: 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->where('status','1');

            foreach ($cl_phones as $value) {

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

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

        return $query->result_array();

}

查看显示空数组Array()

正确的方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要在client_id上使用where_in

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

$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_phone,而不是client_id上使用{{1}}(除非它们相同)

相关问题