Codeigniter where_in OR where_in

fro*_*bak 0 php mysql activerecord codeigniter where-in

我正在使用codeigniter来查询数据库,我需要在where子句中有条件地比较数组.

所以基本上我想做:where_in OR where_in取决于哪个数组中包含数据.所以我将有一个user_id数组或一个area_id数组.

我不确定如何结合where_in比较.这是我需要修改的查询:

public function get_checks_test($org_id,$users,$areas) {
    // get todays date
    $todays_date = date("Y-m-d");
    // build where array
    $check_array = array('c.org_id =' => $org_id, 'c.status !=' => '0', 'c.due <=' => $todays_date);
    // build query
    $this->db->select('c.*,a.check_area_id,b.check_user_id,d.area_name,u.first_name,u.last_name');
    $this->db->order_by('c.due', 'asc');
    $this->db->where($check_array);
    $this->db->where_in('user_id', $users);
    $this->db->or_where_in('area_id', $areas);
    $this->db->join('check_assigned_areas a','a.check_id = c.check_id','left');
    $this->db->join('check_assigned_users b','b.check_id = c.check_id','left');
    $this->db->join('areas d','d.area_id = a.check_area_id','left');
    $this->db->join('users u','u.id = b.check_user_id','left');
    $check_object = $this->db->get('checks c');
    return $check_object->result();
}
Run Code Online (Sandbox Code Playgroud)

我不认为我能找到一个or_where_in函数.

我可以这样做,还是需要重新考虑?

谢谢

Tou*_*han 7

是的,Codeigniter中有一个or_where_in函数.如果需要更多帮助,我很乐意提供帮助.

Thanx,快乐编码.