phpcodeigniteractiverecordwhere-clausewhere-in

CodeIgniter active record syntax: WHERE column equals one of multiple values


My controller (I want to select records based on some conditions) :

public function promotion()
{
    if (!$this->user_permission->check_permission())
        return;

    $data['startDate'] = $this->input->post('input_date_from');
    $data['endDate'] = $this->input->post('input_date_to');
    $email = $this->input->post('email');
        
    var_dump($email);
    var_dump($data['startDate']);
    var_dump($data['endDate']);
    
    $this->db->select('a.booking_id as booking_id, a.from_email as from_email, a.booking_date as booking_date, a.status as status, b.vendor_airway_bill as awb, b.tariff as tariff');
    $this->db->where('from_email', $email);
    $this->db->where('booking_date >=', date('Y-m-d',strtotime($data['startDate'])));
    $this->db->where('booking_date <=', date('Y-m-d',strtotime($data['endDate'])));
    $this->db->where('status = 1');
    $this->db->or_where('status = 2');
    $this->db->from('booking as a');
    $this->db->join('shipment as b','a.booking_id = b.booking_id','left');      
    $query = $this->db->get();
    $data['result'] = $query->result_array();

    $this->template->render('admin/promotion',$data,'admin');
}

I try to filter data based on from_email, date_range_from and date_range_to. When I var_dump the input post, it showing the value as I expected, but it didn't run the this->db->where('from_email',$email), so I get all results.


Solution

  • [SOLVED]. Use where_in() instead of or_where