Query with multiple WHERE and CASE PHP(CodeIgniter) MySQL
23:38 20 Apr 2020

I'd like to select all period of current term (as now FY80) + 3 period only of last term (FY79) from m_period table

Here's the table m_period looks :

+----+------+-------------+--------+
| id | term | period      | status |
+----+------+-------------+--------+
|  1 | FY79 | 79::2020/01 | close  |
|  2 | FY79 | 79::2020/02 | close  |
|  3 | FY79 | 79::2020/03 | close  |
|  4 | FY79 | 79::2020/04 | close  |
|  5 | FY79 | 79::2020/05 | close  |
|  6 | FY79 | 79::2020/06 | close  |
|  7 | FY80 | 80::2020/07 | open   |
|  8 | FY80 | 80::2020/08 | open   |
|  9 | FY80 | 80::2020/09 | open   |
| 10 | FY80 | 80::2020/10 | open   |
| 11 | FY80 | 80::2020/11 | open   |
| 12 | FY80 | 80::2020/12 | open   |
| 13 | FY80 | 80::2021/01 | open   |
| 14 | FY80 | 80::2021/02 | open   |
| 15 | FY80 | 80::2021/03 | open   |
| 16 | FY80 | 80::2021/04 | open   |
| 17 | FY80 | 80::2021/05 | open   |
| 18 | FY80 | 80::2021/06 | open   |
+----+------+-------------+--------+

my php script stuck from here :

session->userdata('term'),2,2) - 1;
    $this->db->select('period');
    $this->db->where('term', $this->session->userdata('term'));
    $this->db->where('term', $prev_term);
    $this->db->order_by('period', 'ASC');
    return $this->db->get('m_period')->result_array();
}

I've read CI documentation and couldn't find how to use CASE in codeigniter, or there is another way instead of using CASE ? can someone help me , how to do this ?

Note : I store current term on session

php mysql codeigniter