title: Add OR WHERE statement in codeigniter using foreach loop
body: <p>I am using codeigniter framework and i want to create a OR WHERE statement using foreach loop,</p>
  
  <p>Below is my code,</p>
  
  <pre><code>$wh_q = array('ec_date &gt;' =&gt; $start, 'ec_date &lt;=' =&gt; $end);
  </code></pre>
  
  <p>This will produce query as <code>WHERE ec_details.date &gt; '2016-11-01 00:00:00' AND ec_details.date &lt;= '2017-01-07 00:00:00'</code></p>
  
  <p>Now i want to append few more criteria in abover query string with AND <code>ec_details</code>.<code>user_id</code> = '5' OR <code>ec_details</code>.<code>user_id</code> = '6' and so on.</p>
  
  <p>Now user_id, 5 and 6 are coming from array results,</p>
  
  <pre><code>$user_string = '5,6';
  $users_array = explode(",",$user_string);
  
  foreach ($users_array as $user) {
     $query = array('ec_details.user_id' =&gt; $user);
  }
  </code></pre>
  
  <p>Then i am merging above <code>$query</code> array in original <code>$wh_q</code> array</p>
  
  <pre><code>$wh_q = array_merge($wh_q, $query);
  </code></pre>
  
  <p>And finally i select where as below,</p>
  
  <pre><code>$this-&gt;db-&gt;where($wh_q);
  </code></pre>
  
  <p>But this will not produce my required query, but will just create like below,</p>
  
  <pre><code>`WHERE `ec_details`.`date` &gt; '2016-11-01 00:00:00' AND `ec_details`.`date` &lt;= '2017-01-07 00:00:00'`AND `ec_details`.`user_id` = '6'`
  </code></pre>
  
  <p>How can i add AND OR WHERE statements using foreach loop in codeigniter?</p>
  
  <p>Thank you,</p>