CodeIgniter Forums
Using joins? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Using joins? (/showthread.php?tid=33652)



Using joins? - El Forum - 09-03-2010

[eluser]chefnelone[/eluser]
Hello,

I'm usign this active record(which works fine):

Code:
$this->db->join('categories', 'categories.id_category = products.category_id'  , 'left');


but... I need to join categories based in the value of $category_id instead of based in the value of of the field: products.category_id.

Something like: (not working)
Code:
$category_id = 228;
$this->db->join('categories', 'categories.id_category = '.$category_id , 'left');


I know I've got a problem with logic of the tables and I'll have to make some changes with them... but I need to solve this now.
Any ideas?
Thanks


Using joins? - El Forum - 09-03-2010

[eluser]Stoney[/eluser]
You can do it like this:
Code:
$this->db->join('categories', 'categories.id_category = products.category_id'  , 'left');
$this->db->where('categories.id_category','228')



Using joins? - El Forum - 09-03-2010

[eluser]Unknown[/eluser]
try this...
$category_id = 228;




Using joins? - El Forum - 09-03-2010

[eluser]chefnelone[/eluser]
cimet solution works fine.
thanks