CodeIgniter Forums
trouble with left join - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: trouble with left join (/thread-32884.html)



trouble with left join - El Forum - 08-08-2010

[eluser]Corbee[/eluser]
Hi,

I'm having sql error saying:

Code:
SELECT * from carmodel LEFT JOIN caryear ON caryear.modelID=carmodel.modelID LEFT JOIN carbrand ON caryear.brandID=carmodel.brandID WHERE brandID = '' AND modelID = ''

This is my code for the model
Code:
$data = array();
$this->db->from('carmodel');
$this->db->join('caryear','caryear.modelID=carmodel.modelID','left');
$this->db->join('carbrand','caryear.brandID=carmodel.brandID','left');
$this->db->where('brandID',$brand);
$this->db->where('modelID',$model);
$q = $this->db->get();    
    if ($q->num_rows() > 0)
    {
        foreach ($q->result_array() as $row)
        {
        $data[] = $row;
        }
    }
$q-> free_result();
return $data;

Does anyone know what's wrong with this? Thanks!


trouble with left join - El Forum - 08-08-2010

[eluser]Corbee[/eluser]
nevermind, I found the error.