kevin gowlett - 2010-02-10 16:48:35
Excuse my ignorance but I'm having difficulty writing the code, the code I have just keeps overwriting the excel file. I'm guessing I need to append the $assoc variable, then fwrite to the file. any help appreciated.
Here is the code.
require_once "excel.php";
$export_file = "xlsfile://./datafran.xls";
//$fp = fopen($export_file, "wb");
$query = "SELECT * FROM newletter";
$results = mysql_query($query) or die(mysql_error());
while ($resultr = mysql_fetch_array ($results, MYSQL_ASSOC)){
$fp = fopen($export_file, "wb");
$assoc = array( $resultr );
var_dump ($assoc).'<br/>';
fwrite($fp, serialize($assoc));
fclose($fp);
// typically this will be generated/read from a database table
/*$assoc = array(
array("Sales Person" => "Sam Jackson", "Q1" => "$3255", "Q2" => "$3167", "Q3" => 3245, "Q4" => 3943),
array("Sales Person" => "Jim Brown", "Q1" => "$2580", "Q2" => "$2677", "Q3" => 3225, "Q4" => 3410),
array("Sales Person" => "John Hancock", "Q1" => "$9367", "Q2" => "$9875", "Q3" => 9544, "Q4" => 10255),
);*/
//printf("ID: %s Email: %s Ident: %s", $resultr["Id_client"], $resultr["E_mail"], $resultr["Identite"]);
}