phpmysqlcodeigniteractiverecordquery-builder

Convert raw MySQL containing a JOIN on identical column names and a WHERE and ORDER BY clause to CodeIgniter active record


I have a MySQL query like this:

SELECT * FROM ms_project_log 
INNER JOIN ms_project ON ms_project_log.iwo_no = ms_project.iwo_no
WHERE  ms_project_log.iwo_no = '0007/NMS/BOTM/01/12'
ORDER BY ms_project_log.log_date DESC

How to convert it to CodeIgniter active record code?


Solution

  • $this->db->join('ms_project','ms_project_log.iwo_no = ms_project.iwo_no','inner')
             ->order_by('ms_project_log.log_date','desc')
             ->get_where('ms_project_log', array('ms_project_log.iwo_no'=>'0007/NMS/BOTM/01/12'))
             ->result_array();
    

    You can filter selected column using select method, by default if not using select method your query will use "select *"