CodeIgniter Forums
correct join syntax for model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: correct join syntax for model (/showthread.php?tid=3067)



correct join syntax for model - El Forum - 09-07-2007

[eluser]kbauman[/eluser]
I'm creating a model, and am wondering if this the correct syntax for a join, with a where, and an orderby.

Code:
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('categories_gallery', 'categories_gallery.gallery_id'='gallery.id');
$this->db->where('categories_id', $this->input->post('category_id');
$this->db->orderby('display_order');
$this->db->get();

or is it this:

Code:
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('categories_gallery', 'categories_gallery.gallery_id'='gallery.id');
$this->db->join('categories_gallery.categories_id'=$this->input->post('category_id');
$this->db->orderby('display_order');
$this->db->get();



correct join syntax for model - El Forum - 09-07-2007

[eluser]zdknudsen[/eluser]
If I am perceiving this right, I'd go with your first guess. Except there is one things that will make PHP badmouth:
Code:
$this->db->join('categories_gallery', 'categories_gallery.gallery_id'='gallery.id')
Which should just be:
Code:
$this->db->join('categories_gallery', 'categories_gallery.gallery_id = gallery.id')

Otherwise I am fairly sure it is right Smile


correct join syntax for model - El Forum - 09-07-2007

[eluser]kbauman[/eluser]
Oh yes, thank you!