Welcome Guest, Not a member yet? Register   Sign In
correct join syntax for model
#1

[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();
#2

[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
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB