Search code examples
phpmysqlcodeigniteractiverecordquery-builder

Convert a SELECT query containing two WHERE conditions to CodeIgniter's active record syntax


I like to convert following MySQL query into a CodeIgniter active record query.

SELECT name,
       address,
       detail,
       status,
       startdate
FROM job_step
WHERE username = '$_SESSION[username]'
      AND status = 0

My job_step table consists of several columns, but I only need a few not the entire table. In addition to that, information should be filtered according to session name and status (TINYINT which has 1 and 0).


Solution

  • You can write the above query as:

    $this->db->select('name, address, detail, status, startdate');
    $this->db->where('username',$_SESSION['username']);
    $this->db->where('status','0');
    $rset=$this->db->get('job_step');
    $result=$rset->result();