In my database is a table consisting of job results that I would like to compile and display. The user will have 2 options for the displayed report, with and without details. So the query will pull all the rows from the table, combine all the values for a particular company name and display the company name as well as the various totals for other columns all combined for the non-detailed report.

If they choose the detailed report I would like to insert more rows between each company name with the per job results.

Here are some examples (the numbers may not be accurate, this is just to give an idea of the results I am wanting):

Non-Detailed report:
Company Name Job Amount Labor Materials Balance
ACME $20,000 $5,000 $4,000 $11,000
Farming LLC $15,000 $6,000 $7,000 $2,000
WidgetCo $10,000 $2,000 $4,000 $4,000

Detailed report:
Company Name Job Amount Labor Materials Balance
ACME $20,000 $5,000 $4,000 $11,000
31001 - JobDescription $4,000 $1,000 $500 $2,500
31293 - JobDescription $6,000 $2,000 $2,00 $2,000
31547 - JobDescription $10,000 $2,000 $1,500 $6,500
Farming LLC $15,000 $6,000 $7,000 $2,000
31228 - JobDescription $15,000 $6,000 $7,000 $2,000
WidgetCo $10,000 $2,000 $4,000 $4,000
31179 - JobDescription $3,500 $1,250 $1,500 $750
31473 - JobDescription $6,500 $750 $2,500 $3,250

Can someone suggest how best to build the MySQL queries to pull this data, and I'm also not exactly sure of the best method to store it (array(s) or whatever) to ease iteration through the results when constructing the HTML page for the end user.

Thanks in advance for any guidance anyone can offer.

Greg