RE: MySQL to Excel using PHP More Questions (Pivot Tables)

From: Date: Wed, 01 May 2002 18:25:42 +0000
Subject: RE: MySQL to Excel using PHP More Questions (Pivot Tables)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-95557@lists.php.net to get a copy of this message
[snip] /path/to/php_to_excel.php/excel.xls [/snip] OK, that solves that problem and is easy to implement. The problem I have now is creating pivot tables from the information. I'll use my previous example; SELECT RecordID, RecordDate, count(*) AS Quantity FROM tblFOO Group By RecordID, RecordDate It returns; +----------+------------+----------+ | RecordID | RecordDate | Quantity | +----------+------------+----------+ | 100101 | 2002-03-21 | 6675 | | 100101 | 2002-03-22 | 6794 | | 100101 | 2002-03-23 | 2916 | | 100101 | 2002-03-24 | 1215 | | 100101 | 2002-03-25 | 6152 | | 100101 | 2002-03-26 | 5398 | +----------+------------+----------+ as expected (Only a subset here, there are hundreds of rows). I want to place this data like this in an Excel table (bad ascii art example to follow); +------------+--------+--------+--------+ | RecordID | 100101 | 100120 | 100131 | +------------+--------+--------+--------+ | Date | | | | +------------+--------+--------+--------+ | 2002-03-01 | | 12 | 130101 | +------------+--------+--------+--------+ | 2002-03-21 | 6675 | | 1113 | +------------+--------+--------+--------+ | 2002-03-22 | 6794 | 287 | 29045 | +------------+--------+--------+--------+ | 2002-03-23 | 2916 | 6 | 233427 | +------------+--------+--------+--------+ RecordID along the top row, dates down the side, quantities at the intersection that they belong. Importing the original table into Excel is no big deal, but getting the table to pivot form is a nasty bit of business. I did run seperate queries for RecordID and did a while loop to place them as column heads, likewise with RecordDate to place in the first column of each row. Could I write the query out to an array and then place the values properly? I am at a loss here. Thanks! Jay Blanchard

« previous php.general (#95557) next »