My table looks like this:
artist_id | song_id | user_id
a1 s1 u1
a1 s2 u1
a2 s9 u1
a3 s15 u2
I'd like my output to look something like:
Array
(
[u1] => Array
(
[a1] => Array
(
[0] => s1
[1] => s2
)
[a2] => Array
(
[0] => s9
)
)
[u2] => Array
(
[a3] => Array
(
[0] => s15
)
)
)
Where should I start?
I'm not sure my approach is most efficient:
Grab and group
user_id
, loop thru them.For each
user_id
, grab theartist_id
.For each
artist_id
grab thesong_id
s underneath.
Is there a way to make this one query?