[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();
foreach($collections->result_array() as $row){
$arrayCollections[$row['collection_id']] = $row;
}
$boxsets = $this->boxset_model->get_all_boxsets();
foreach($boxsets->result_array() as $row){
$arrayCollections[$row['collection_id']]['boxsets'][] = $row;
}
$cds = $this->cd_model->get_all_cds();
foreach($cds->result_array() as $row){
........
........
}
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 ;-)