I have this php code:
$query_production = "SELECT uploadedby as name, sum(points) as points,
date_format(uploaddate,'%Y-%m-%d') as date FROM imsexport
WHERE uploaddate BETWEEN '2014-01-01 00:00:00' and '2014-01-20 23:59:59'
GROUP BY uploadedby,date";
$result_production = mysql_query($query_production);
$row_production = mysql_fetch_assoc($result_production);
The HTML Table output is
name points date
John 147 2014-01-01
Bob 79 2014-01-01
Joe 156 2014-01-01
Sue 116 2014-01-01
John 117 2014-01-02
Bob 186 2014-01-02
Sue 74 2014-01-02
Bob 233 2014-01-03
John 159 2014-01-03
Sue 162 2014-01-03
Bob 162 2014-01-04
Sue 38 2014-01-05
How can I pivot this table to look display like this using php? I've already done this using mysql but the code is too long.
Name |2014-01-01|2014-01-02|2014-01-03|2014-01-04|2014-01-05
Bob 79 186 233 162 0
Joe 156 0 0 0 0
John 147 117 159 0 0
Sue 116 74 162 0 38
ORDER BY name, dateyou will have the data in the right order and you can loop through it, building your table and adding zero values where no results exist and new rows where the name changes.