Select as with non unique results - 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: Select as with non unique results (/showthread.php?tid=28822) |
Select as with non unique results - El Forum - 03-22-2010 [eluser]Ty Bex[/eluser] I am joining 2 tables with columns that have the same name "NAME" and "ID" The problem is I would expect to get the name and id from each product according to my select. Is there a way to get the result of each column that I am selecting? TABLE ecom_product Code: ----------------------------------------- TABLE ecom_level Code: ----------------- Code: $this->db->select('p.id, p.active, p.name, l.name'); RESULT stdClass Object ( [id] => 3 [active] => 1 [name] => Senior ) Select as with non unique results - El Forum - 03-22-2010 [eluser]Ty Bex[/eluser] Never mind.. Instead of being a lazy coder I fixed the database structure.. Select as with non unique results - El Forum - 03-23-2010 [eluser]danmontgomery[/eluser] Just to explain this (even though you found a different solution), even though you are differentiating between tables for the "name" column, the table name isn't included in the result, so you were getting back 2 "name" columns, and PHP doesn't handle non-unique array keys. The simple solution would be to just assign aliases for the result columns: Code: $this->db->select('p.id AS p_id, l.id AS l_id, p.active, p.name AS p_name, l.name AS l_name'); |