Hello -
I’m working with a database that has a list of records and I am looking to display some of that data in a table, organized by username, from left to right instead of top to bottom. This is the table I’m working with:
--------------------------------------
| ID | SubmitBy | SubmitDate | Score |
--------------------------------------
| 01 | User1 | June 10 | 90 |
--------------------------------------
| 02 | User2 | June 10 | 88 |
--------------------------------------
| 03 | User1 | June 12 | 93 |
--------------------------------------
| 04 | User2 | June 12 | 97 |
--------------------------------------
| 05 | User3 | June 13 | 89 |
--------------------------------------
What I need to do is display the scores for each user from older records to newer records, left to right, on a table that is organized by the user’s name, like so:
------------------------------------
| User | Score1 | Score2 | Score3 |
------------------------------------
| User1 | 90 | 93 | 97 |
------------------------------------
| User2 | 88 | 97 | |
------------------------------------
| User3 | 89 | | |
------------------------------------
To make this more complicated, the table has 10 scores on it, so for any user that doesn’t have 10 scores in the database table I need to have the remaining table cells populated / created to fill in the rest of the table code for that row.
I’m not exactly sure how to craft the MySQL request for this, nor the code to display the data the way I need to. I originally thought I could just do a “SELECT * FROM table ORDER BY SubmitBy” and then try to use a “foreach”, but I can’t figure out how to craft the request properly it seems - and that might not be the proper way to do this either.
Any help would be greatly appreciated!