I would like to get, for each type, the number of occurrences. You can see in the image that they are positioned at difference places based on a COUNT query I'm doing to get the data.

I am using CodeIgniter, and this is my current code, but it doesn't work.
foreach ($query->result() as $row) {
$num = $row->type;
$returndata[] = array(
'type' => $row->type,
'num' => $row->TYPE.$num
);
}
I was thinking that I could get the data with a simple foreach loop but apparently I can't. Is there some secret voodoo magic, apart from using a switch statement, to get the data?
$returndataafter your loop is over?type. BTW your edit is inaccurate (switch -> foreach). I meant that first thing that came to my mind was to create a switch and check the type of $row->num and based on that get a different TYPE1.2.3....apart from using a switch loop:switchin the first place is not a loop at all, it is a conditional structure. Secondly the code that you presented as your attempt has aforeachloop and no switch statement anywhere. Besides, if you consider this edit changes the meaning of what you stated, please revert it back with an apology from my side