Assume I have the following result set from a mysql DB call (basic example, main will have much more data):
customerID | name | item | price
====================================================
11111 | John | pizza | 10.00
11111 | John | burger | 5.00
11111 | John | drink | 2.00
22222 | Mike | lasagna | 11.00
22222 | Mike | drink | 2.00
33333 | Sam | burger | 5.00
33333 | Sam | fries | 3.00
33333 | Sam | shake | 5.00
33333 | Sam | drink | 2.00
I want to display the results in a tabular form but limit the times customerID and name appear, as well as show a subtotal by each customer:
customerID | name | item | price
===================================================
11111 | John | pizza | 10.00
| | burger | 5.00
| | drink | 2.00
| | | **17.00**
| | |
22222 | Mike | lasagna | 11.00
| | drink | 2.00
| | | **13.00**
| | |
33333 | Sam | burger | 5.00
| | fries | 3.00
| | shake | 5.00
| | drink | 2.00
| | | **15.00**
I know I could make multiple DB calls but this is wasteful when it can be done in one. I am having problems cycling through my result set in table 1 and properly formatting with PHP using as shown in table 2. Is it possible the way I have it shown or do I have to make multiple DB calls to do so?
This is better solved directly in PHP, because you will be free to modify the output as you wish.
So basically you will do something like (untested):