Single HTML Table from multiple MySQL tables

Posted by David Chouinard on Stack Overflow See other posts from Stack Overflow or by David Chouinard
Published on 2010-04-14T01:27:39Z Indexed on 2010/04/14 1:33 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

Hi!

I've been struggling for a while with this one; I'll try to explain it here as simply as possible.

Consider 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 keys making reference to a primary key in another table. The same pilot_id can be associated with different session_id, but every pilot_id-session_id combination is unique.

I need to make an HTML table (in PHP) that would display the data like this:

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

Hence, rows are pilot_id and columns are session_id. When a pilot_id-session_id combination has a present value of 1, the corresponding cell should be checked. (ie. when the row-combination is zero or the combination does not exist in the MySQL table, nothing should appear in the HTML table)

Phew.

Any ideas?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about php5