CodeIgniter Forums
Tranform mysql sql into codeigniter query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Tranform mysql sql into codeigniter query (/thread-73347.html)



Tranform mysql sql into codeigniter query - alexandrutoader - 04-13-2019

Hello,

I have this mysql select:

Code:
SELECT id, zile, status, nr_inmatriculare,title,start_date,end_date,doc_type, contact_emails
           FROM (SELECT datediff(cd.end_date,curdate())  as zile, c.id,
                      c.nr_inmatriculare, c.status,cd.title,cd.end_date,cd.start_date, cd.doc_type, c.contact_emails
                         FROM car_docs cd
                         INNER JOIN cars c ON c.id = cd.car_id
                         WHERE c.status > 0

                       ) as s WHERE zile > -2190 AND title LIKE 'ITP' ORDER BY zile ASC
 
And I'm trying to tranform it into codeigniter query this is what I done:

Code:
return $this->db->select('id, zile, status, nr_inmatriculare,title,start_date,end_date,doc_type, contact_emails')
                   ->where('DATEDIFF(cd.end_date, current_date) as zile, c.id, c.nr_inmatriculare, c.status, cd.title, cd.end_date, cd.start_date, cd.doc_type, c.contact_emails')
                   ->from('car_docs cd')
                   ->join('cars c','c.id = cd.car_id','inner')
                   ->where('c.user_id',$this->session->userdata['user_id'])
                   ->where('c.status >',0)
                   ->where('zile >' ,-2190)
                   ->like('title', 'ITP')
                   ->order_by('zile', 'ASC')
                   ->get()->result();

But is not working. What I need to change?


RE: Tranform mysql sql into codeigniter query - dave friend - 04-13-2019

Please explain what "not working" means.
What, if any errors are you getting?
How are the results not what is expected?