I cannot wrap my head around this:
I need to write out a query to an Excel file. I found these classes ported over from Perl here: http://www.bettinga-attack.de/jonny/projects/php_writeexcel/
Now, the arguement for the write-function has to be a cell reference. So, I got aroudn this by making a simple count loop. The problem is, it will loop through and write the proper number of rows and columns, but onyof the last entry of the query. Thats is to say, it writes the last field 10-times (as many fields as there are). I tried mysql_fetch_array, row and assoc and they all do the same thing. I'm sure its something simple
<?php
include "../db.inc";
set_time_limit(1000);
require_once "../classes/excel/class.writeexcel_workbook.inc.php";
require_once "../classes/excel/class.writeexcel_worksheet.inc.php";
$db = mysql_connect($hostname,$user,$password);
mysql_select_db($databasename,$db);
$result = mysql_query("SELECT * FROM table",$db);
$count = mysql_num_fields($result);
$filename = $HTTP_GET_VARS["id"] . '-' . date("ymdhms") . '.xls';
$workbook = &new writeexcel_workbook($filename);
$worksheet = &$workbook->addworksheet();
while ($res_array = mysql_fetch_row($result)) {
for ($i = 0; $i < $count; $i++){
$worksheet->write_row($i, 0, $res_array);
}
}
$workbook->close();
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=tester.xls");
$fh=fopen($filename, "rb");
fpassthru($fh);
unlink($filename);
?>