Formatting sql query rows as columns with stack
Hello!
Here's a non-trivial problem I faced recently.
I have two tables: Users and Transports. Users is obvious, Transport stores transport data (date, place, case_no, user).
Users
----------
01|Tom |
02|Martin|
03|Maggie|
04|Chris |
Transports
----------
01|2004-09-12|Italy|03/05|Martin|
02|2004-10-02|France|04/05|Tom|
03|2004-10-06|Italy|07/05|Martin|
04|2004-10-14|Germany|08/05|Maggie|
05|2004-10-14|Belgium|09/05|Maggie|
06|2004-10-15|Austria|10/05|Martin|
etc.
What I would like to do is to make an HTML table with Users as columns and transports as rows, BUT I would like to show one transport per user in each row so that it make a sort of an inverted stack. The output should look like this:
| Tom | Martin | Maggie | Chris |
-------------------------
|2004-10-02, France, 04/05|2004-09-02, Italy, 03/05 |2004-10-14, Germany, 08/05| |
| |2004-10-06, Italy, 07/05 |2004-10-14, Belgium, 09/05| |
| |2004-10-15, Austria, 10/05| | |
etc.
My question is: how to get such a result using PHP instructions. I suppose it would require some multidimensional array manipulations. Does anyone have any idea how to do it?
I'll be very grateful for any help.
Best regards,
Sebastian
|