Aditya Lepcha Aditya Lepcha - 6 months ago 34
MySQL Question

Codeigniter Active Record, Multiple where conditions

Here is my table structure. and I want to get records between provided date range.

|--------------|---------------------|
| id | year | month |
|--------------|---------------------|
| 1 | 2015 | 01 |
| 2 | 2015 | 02 |
| 3 | 2016 | 02 |
|--------------|---------------------|


I tried with following query, but didn't work.

return $this->db->select('*')
->from('tourist T')
->where('T.year >=', $where['s_year'])
->where('T.month >=', $where['s_month'])
->where('T.year <=', $where['e_year'])
->where('T.month <=', $where['e_month'])
->get()->result();

Answer

Try This:

   $this->db->select('*')
            ->from('test T')
            ->where('T.year >='.$where['s_year'].' and T.month >='.$where['s_month'])
            ->where('T.year <='.$where['s_year'].' and T.month <='.$where['s_month'])
            ->get()->result();