Forum Moderators: coopster

Message Too Old, No Replies

Dynamic Crosstab Query

Crosstab

         

Arfi

10:54 am on Jun 22, 2012 (gmt 0)

10+ Year Member



Dear ALL Web Master
newbie as I am need your help
table_1
+-------------+-----+---+
| i_date | num |val|
+-----------------------+
| 2012-07-01 | 201 | 1 |
| 2012-07-02 | 201 | 1 |
| 2012-07-03 | 201 | 1 |
| 2012-07-01 | 202 | 1 |
| 2012-07-02 | 202 | 1 |
| 2012-07-01 | 203 | 0 |
| 2012-07-02 | 203 | 0 |
| 2012-07-03 | 203 | 0 |
| 2012-07-01 | 204 | 0 |
| 2012-07-02 | 204 | 0 |
| 2012-07-03 | 204 | 0 |

How do i use PHP to crosstab the table_1 and echo it to the page to be:
+-----+--------------+-------------+-------------+
| num | 2012-07-01 | 2012-07-02 | 2012-07-03 |
+-----+--------------+-------------+-------------+
| 201 | 1 | 1 | 1 |
| 202 | 1 | 1 | 0 |
| 203 | 1 | 1 | 1 |
| 204 | 0 | 0 | 0 |
+-----+--------------+-------------+-------------+

somehow i would like to entry some rows on table_1 with a new date using a form. I wish i could view it (continuing) on the page.

Big Thanks for all you guys.

rocknbil

4:09 pm on Jun 22, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Work it out in mysql first. Try

select i_date, num, val from table group by val;