EllisLab text mark
Advanced Search
     
correct join syntax for model
Posted: 07 September 2007 04:59 PM   [ Ignore ]
Joined: 2007-03-21
25 posts

I’m creating a model, and am wondering if this the correct syntax for a join, with a where, and an orderby.

$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:

$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(); 
 
Posted: 07 September 2007 05:19 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-16
319 posts

If I am perceiving this right, I’d go with your first guess. Except there is one things that will make PHP badmouth:

$this->db->join('categories_gallery''categories_gallery.gallery_id'='gallery.id'

Which should just be:

$this->db->join('categories_gallery''categories_gallery.gallery_id = gallery.id'

Otherwise I am fairly sure it is right smile

 Signature 

Best regards. Zacharias.
Matchbox (Modular Separation) | Wick (Controller Loader)

 
Posted: 07 September 2007 05:23 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-03-21
25 posts

Oh yes, thank you!