CodeIgniter : how to write where_in OR where_in query?
<p>I'm using codeigniter to query a database, and I need to conditionally compare arrays in the where clause.</p>

<p>So basically I want to do: where_in OR where_in depending on what array has data in it. So I will have either an array of user_id OR an array of area_id's.</p>

<p>I'm not sure how to combine the where_in comparison. This is the query i need to amends:</p>

<pre><code>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 =' =&gt; $org_id, 'c.status !=' =&gt; '0', 'c.due &lt;=' =&gt; $todays_date);
    // build query
    $this-&gt;db-&gt;select('c.*,a.check_area_id,b.check_user_id,d.area_name,u.first_name,u.last_name');
    $this-&gt;db-&gt;order_by('c.due', 'asc');
    $this-&gt;db-&gt;where($check_array);
    $this-&gt;db-&gt;where_in('user_id', $users);
    $this-&gt;db-&gt;or_where_in('area_id', $areas);
    $this-&gt;db-&gt;join('check_assigned_areas a','a.check_id = c.check_id','left');
    $this-&gt;db-&gt;join('check_assigned_users b','b.check_id = c.check_id','left');
    $this-&gt;db-&gt;join('areas d','d.area_id = a.check_area_id','left');
    $this-&gt;db-&gt;join('users u','u.id = b.check_user_id','left');
    $check_object = $this-&gt;db-&gt;get('checks c');
    return $check_object-&gt;result();
}
</code></pre>

<p>I don't think there is a or_where_in function that I can find.</p>

<p>Can I do it like this or do I need a rethink?</p>

<p>Thanks</p>