I'm using php to draw some record from my mysql table and make a csv file. The table contain is sorted with different currencies. I've to create a csv file which groups a currency and have a total of each currency. For example, the csv file should look like this,

CDN,1000
CDN,1340
total,2340
USD,450
USD,300
USD,600
total,1350

I wonder if there is a php API for Mysql that I can look ahead the upcoming record in my table, so that I can find the next currency in order to create the "total" line for my csv file. Thanx!