I have the following result set
ID SUBID DATA
1 0 Question1
1 1 Option1
1 2 Option2
2 0 Question1
2 1 Option1
2 2 Option2
...
I really want an array that looks like this
$item_data[1][1] = ID 1
$item_data[1][2] = Question1 <br> Option1 <br> Option2
$item_data[2][1] = ID 2
$item_data[2][2] = Question2 <br> Option1 <br> Option2
I have racked my brains trying loops within loops and string concatination but I just cant get my result set to look like this
Im trying to get it into one array so I can then out put the data – its important that the data stays together but different ID’s are selerate from each other
SubID is not used – the table looks like this due to db design which I cant change
select iseg.item_id ,iseg.item_subid, iseg.item_data from items i
inner join item_data iseg on iseg.item_id = i.item_id
union all
select iseg.item_stg_id ,iseg.item_subid, iseg.item_data from items_stg i
inner join item_data_stg iseg on iseg.item_stg_id = i.item_stg_id
order by iseg.item_id desc, iseg.item_subid
The Item data needs parsing in PHP first before concatination
Assuming
$resultsetis your mysql result set, you could do as follows:In your example there are only three rows for each ID, but my above code allows for any number of rows with same ID, so that could be important if that case could happen.