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