I'm fairly new to php and I'm looking for some help on control structures. What I want to do, as elegantly as possible, is to accumulate various totals by month.
the db has records like
Date Type Amt
2005-11-15 AAA 15
2005-11-16 AAA 17
2005-11-16 BBB 18
2005-12-01 CCC 25
Form that, I'd want to get the results of:
Month Type Total
11 AAA 32
11 BBB 18
12 CCC 25
Back in my old COBOL (showing me age) days I'd have done something like this:
PERFORM READ-FILE (File sorted by Date and Type)
PERFORM STORE-CURRENT-MONTH-TYPE.
PERFORM UNTIL END-OF-FILE
...PERFORM UNTIL CURRENT-KEY > STORE-KEY
........PERFORM ACCUMULATE-TYPE
........PERFORM READ-FILE
...END-PERFORM
...PERFORM PRINT-TOTALS
...PERFORM STORE-CURRENT-MONTH-TYPE
END-PERFORM
PERFORM PRINT-TOTALS
What would be the most elegant way to do this in php? The foreach method wouldn't let me get and store the first returned record, would it?
Any help greatly appreciated.