I have been battling for some time with that one I'll attempt to explain it because simply as you possibly can.

Think about this MySQL table:

+----------+-----------+---------+--------+
|status_id |session_id |pilot_id |present |
+----------+-----------+---------+--------+
|1         |61         |901      |1       |
|2         |63         |901      |1       |
|3         |62         |901      |0       |
|4         |62         |902      |1       |
|5         |63         |903      |1       |
+----------+-----------+---------+--------+

Both session_id and pilot_id are foreign secrets making mention of the a principal type in another table. Exactly the same pilot_id could be connected with various session_id, but every pilot_id-session_id combination is exclusive.

I have to make an HTML table (in PHP) that will display the information such as this:

+----------+---------+---------+---------+
|          |61       |62       |63       |
+----------+---------+---------+---------+
|901       |X        |         |X        |
|902       |         |X        |         |
|903       |         |         |X        |
+----------+---------+---------+---------+

Hence, rows are pilot_id and posts are session_id. Whenever a pilot_id-session_id combination includes a present worth of 1, the related cell ought to be checked. (ie. once the row-combination is zero or even the combination doesn't appear in the MySQL table, nothing should come in the HTML table)

Phew.

Any ideas?

Thanks!


I have attempted the solution suggested by erisco, but I am quite confused. (the comment area is a lot not big enough for my explanation, hence this update to my question).

This is actually the actual data I'm dealing with:

+----------+-----------+---------+--------+
|status_id |session_id |pilot_id |present |
+----------+-----------+---------+--------+
|7         |65         |33       |1       |
|8         |66         |33       |1       |
|9         |65         |17       |0       |
|10        |66         |16       |1       |
+----------+-----------+---------+--------+

I personally use $rows = mysqli_fetch_array($result);. I've confirmed the totally coming back the best data.

However, after i make use of the answer suggested by ericso, I get apparently arbitrary data. Here's the produced HTML table:

+----------+---------+---------+---------+---------+
|          |1        |3        |6        |7        |
+----------+---------+---------+---------+---------+
|1         |X        |         |         |         |
|3         |         |         |         |         |
|6         |         |         |         |         |
|7         |         |         |         |         |
+----------+---------+---------+---------+---------+

In addition the 'X' position stays exactly the same irrelevantly of present values.

Any ideas why this really is happening?

Thanks!