I have the following data being returned from my database query:
+---------------+-----------+------------------+--------------+-------+ | district_name | school_id | school_name | section | score | +---------------+-----------+------------------+--------------+-------+ | My ISD | 11 | My First School | English | 20 | | My ISD | 11 | My First School | Math | 23 | | My ISD | 11 | My First School | Reading | 24 | | My ISD | 11 | My First School | Science | 23 | | My ISD | 12 | My Second School | English | 11 | | My ISD | 12 | My Second School | Math | 19 | | My ISD | 12 | My Second School | Reading | 22 | | My ISD | 12 | My Second School | Science | 26 | +---------------+-----------+------------------+--------------+-------+
I need to put this data into an array to easily output a table of scores by school:
School English Math Reading Science ------------------------------------------------------- My First School 20 23 24 23 My Second School 11 19 22 26
I'm having trouble formatting this data into an array that accomplishes this. The ideal structure would be:
array(
$schoolName => array(
'results' => array(
'section' => $section_name
'score' => $score
),
),
);
I've tried several approaches but can't get them to work correctly.