Help with join tables - 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: Help with join tables (/showthread.php?tid=32740) |
Help with join tables - El Forum - 08-03-2010 [eluser]Unknown[/eluser] Hello !, I need help with query. I have two tables: table: ron ----------------- |id | label | |-----------------| | 1 | one | |-----------------| | 2 | two | |-----------------| | 3 | three | |-----------------| | 4 | four | ----------------- table: ron_data ---------------------------------------- | id | level1 | level2 | level3 | level4 | |----------------------------------------| | 1 | id1 | id2 | id3 | id4 | |----------------------------------------| | 2 | id3 | id4 | id1 | id2 | |----------------------------------------| | 3 | id1 | id4 | id3 | id2 | |----------------------------------------| | 4 | id4 | id2 | id3 | id1 | ---------------------------------------- I want to join these two tables (every value from ron_data in field level1, level2, level3, level4 is id from table ron. i want result: ---------------------------------------- | id | level1 | level2 | level3 | level4 | |----------------------------------------| | 1 | one | two | three | four | ---------------------------------------- I am using statement join: $this->db->where('ron_data.level1', $segm); if($segm1<>''){$this->db->where('ron_data.level2', $segm1);} if($segm2<>''){$this->db->where('ron_data.level3', $segm2);} if($segm3<>''){$this->db->where('ron_data.level4', $segm3);} $this->db->select('ron_data.*, ron.id AS label_id, ron.label AS label'); $this->db->join('ron', 'ron_data.level1 = ron.id '); $query=$this->db->get('ron_data'); With this code i get only first column level1 joined. Please help Help with join tables - El Forum - 08-04-2010 [eluser]Jan_1[/eluser] why that if-clause? what is your searchkey '$segm1'? label or id of ron? Help with join tables - El Forum - 08-05-2010 [eluser]danmontgomery[/eluser] Code: $this->db->join(‘ron’, ‘ron_data.level1 = ron.id ‘); Because you're only joining on level1... Code: $this->db->select('ron_data.id, l1.label AS level1, l2.label AS level2, l3.label AS level3, l4.label AS level4', FALSE) |