Grouping income data into months (and years)

Hi!

I have a mysql table with the following headings for the daily takings in our shop:

date // nettax1 // nettax2 // nettax3 // tax1 // tax2

The entries span over a few years and I would like to run reports which group the months (and years) into separate headings, e.g:

September 2009
01 // 316.43 // 95.53 // 27.46
02 // …
03 // …

August 2009
01 // …
02 // …
03 // …

July 2009
01 // …
02 // …
03 // …

Etc.

Any ideas?

Many thanks.


$groups = array();
while ($row = fetch_assoc_from_db_result()) {
    list($y, $m, $d) = split_mydate_into_parts($row['date']);
    $groups[$y][$m][$d][] = $row;
}

//print_r($groups);

foreach ($groups as $year => $months) {
    echo "$year\
";
    foreach ($months as $day => $records) {
        echo "  $month\
";
        foreach ($records as $record) {
            echo "    $record[tax1] $record[tax2] ... \
";
        }
    }
}

You’ll need to fill in the functions, but that’s the logic.