Skip to content
Advertisement

PHP MYSQL Results into a table

I have a PHP/MySQL query that returns the following:

JavaScript

The months return in an ordered fashion (E.g. January records are always before February records). However, not every user will have a result every month (see above).

And I want my data to present such as this, in an html table:

JavaScript

Here is my (non working) attempt:

JavaScript

Which unfortunately results in results such as this:- enter image description here

What would be the best way to achieve this? I have tried storing the position of each user in the table headers, but then it is difficult to know how many empty columns to add before and the entry (see image above).

Advertisement

Answer

just a quick update. I have managed to get what I desired through the following code

JavaScript

Essentially I created 3 arrays. An array of users, an array of months, and an array of all data (3d array). I use the months and users to record the order in which the tables should be presented. I then loop through my 3d array and print the relevant data.

Despite the downvotes, I would like to thank you all for offering your help. If you have any recommendations please let me know.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement