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:
[table=“width: 500, class: grid, align: right”]
[tr]
[td]Company Name[/td]
[td]Job Amount[/td]
[td]Labor[/td]
[td]Materials[/td]
[td]Balance[/td]
[/tr]
[tr]
[td]ACME[/td]
[td]$20,000[/td]
[td]$5,000[/td]
[td]$4,000[/td]
[td]$11,000[/td]
[/tr]
[tr]
[td]Farming LLC[/td]
[td]$15,000[/td]
[td]$6,000[/td]
[td]$7,000[/td]
[td]$2,000[/td]
[/tr]
[tr]
[td]WidgetCo[/td]
[td]$10,000[/td]
[td]$2,000[/td]
[td]$4,000[/td]
[td]$4,000[/td]
[/tr]
[/table]
Detailed report:
[table=“width: 500, class: grid, align: right”]
[tr]
[td]Company Name[/td]
[td]Job Amount[/td]
[td]Labor[/td]
[td]Materials[/td]
[td]Balance[/td]
[/tr]
[tr]
[td]ACME[/td]
[td]$20,000[/td]
[td]$5,000[/td]
[td]$4,000[/td]
[td]$11,000[/td]
[/tr]
[tr]
[td]31001 - JobDescription[/td]
[td]$4,000[/td]
[td]$1,000[/td]
[td]$500[/td]
[td]$2,500[/td]
[/tr]
[tr]
[td]31293 - JobDescription[/td]
[td]$6,000[/td]
[td]$2,000[/td]
[td]$2,00[/td]
[td]$2,000[/td]
[/tr]
[tr]
[td]31547 - JobDescription[/td]
[td]$10,000[/td]
[td]$2,000[/td]
[td]$1,500[/td]
[td]$6,500[/td]
[/tr]
[tr]
[td]Farming LLC[/td]
[td]$15,000[/td]
[td]$6,000[/td]
[td]$7,000[/td]
[td]$2,000[/td]
[/tr]
[tr]
[td]31228 - JobDescription[/td]
[td]$15,000[/td]
[td]$6,000[/td]
[td]$7,000[/td]
[td]$2,000[/td]
[/tr]
[tr]
[td]WidgetCo[/td]
[td]$10,000[/td]
[td]$2,000[/td]
[td]$4,000[/td]
[td]$4,000[/td]
[/tr]
[tr]
[td]31179 - JobDescription[/td]
[td]$3,500[/td]
[td]$1,250[/td]
[td]$1,500[/td]
[td]$750[/td]
[/tr]
[tr]
[td]31473 - JobDescription[/td]
[td]$6,500[/td]
[td]$750[/td]
[td]$2,500[/td]
[td]$3,250[/td]
[/tr]
[/table]
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