Problem with SQL JOIN and CI query results - 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: Problem with SQL JOIN and CI query results (/showthread.php?tid=39072) |
Problem with SQL JOIN and CI query results - El Forum - 02-28-2011 [eluser]dandys997[/eluser] Hi! I've got a three tables in MySQL database, for example: - movie, - user, - category. I need to join them, so I use a model's method with this code Code: $this->db->order_by("date"); As a result I get an object: $query. Now I can easily access the query's data, for example: Code: $row=$query->row(); But there's a one problem: tables "category" and "user" have one the same named field: "name". How could I access field from above query with selecting source table? This code: Code: $row->category.name doesn't work. Thanks in advance for help! Problem with SQL JOIN and CI query results - El Forum - 02-28-2011 [eluser]Media Gearhead[/eluser] You will need to add a select to the query... Like so. Code: $this->db->select('movie.name as moviename,user.name as username,category.name as categoryname,movie.*,user.*,category.*); The as will allow you to set it to what you need it to be and you would be able to reference them as $row->moviename $row->username $row->categoryname Hope this helps. Problem with SQL JOIN and CI query results - El Forum - 02-28-2011 [eluser]dandys997[/eluser] Thanks a lot! It works. |