Coming from another question of mine where I learnt not to EVER use db queries within loops I consequently have to learn how to fetch all the data in a convenient way before I loop through it.
Let's say I have two tables 'scales' and 'items'. Each item in items belongs to one scale in scales and is linked with a foreign key (scaleID). I want to fetch all that data into an array structure in one query such that the first dimension are all the scales with all the columns and nested within, all items of one scale all columns.
Result would be something like that:
scale 1, scaleParam1, scaleParam2, ...
....item1, itemParam1, itemParam2, ...
....item2, itemParam1, itemParam2, ...
scale 2, scaleParam2, scaleParam2, ...
....item1, itemParam1, itemParam2, ...
....item2, itemParam1, itemParam2, ...
So far I've done mainly left joins for one-to-one relationships. This is a one-to-many and I just can't wrap my mind around it. Is it a right join, could it also be done with a subquery, how to get the full outer rows into it as well...
later I would like to iterate through it with to nested foreach loops.
Maybe it's just that I have a headache...