![]() |
Parent-Child-Grandchild Hierarchy - 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: Parent-Child-Grandchild Hierarchy (/showthread.php?tid=52171) |
Parent-Child-Grandchild Hierarchy - El Forum - 05-31-2012 [eluser]NikosV[/eluser] Here's my problem. I have 3 tables in my database. Collections, Boxsets and CDs. These tables are connected as following: A Collection has one or more Boxsets A Boxset has one or more CDs I created the following columns to each table: Collections collection_id - collection_title Boxsets boxset_id - boxset_title - collection_id CDs cd_id - cd_title - boxset_id I am trying to get all available data and structure these data in an array in this manner: -Collection 1 --Boxset1 ---CD 1 ---CD 2 --Boxset 2 ---CD 1 ... -Collections 2 .... I am going fine for the first two tables using the code below: Code: $collections = $this->collection_model->get_all_collections(); How should i add the third table (CDs) since the collection_id will no longer be available when i get the CDs? Should i add a collection_id field in CDs table? Is there another way to achieve the same result? Thanks in advance for your help ;-) Parent-Child-Grandchild Hierarchy - El Forum - 05-31-2012 [eluser]NikosV[/eluser] no answers? i thought that would be easy.. Parent-Child-Grandchild Hierarchy - El Forum - 06-01-2012 [eluser]NikosV[/eluser] My solutions so far is creating two different arrays. However it doesn't look as the optimal solution. Any suggestions fore improvements? Code: $collections = $this->collection_model->get_all_collections(); |