Forum Moderators: coopster

Message Too Old, No Replies

mysql to excel and then email the excel doc

         

jlenting

8:48 am on Oct 7, 2005 (gmt 0)



Hello all,

I have a good working code for making a excel doc. on the fly. He send the file to the screen and you can save it directly. But I dont want it to send it to the screen but that he save it on the server and EMAILS it to someone. I'm searching and trying to get it work for 3 days, but no luck. I hope you guys can help me out.

This is the code I use the make an excel doc.


$select = "SELECT * FROM dagrapport WHERE dagrapportid='$dagrapportid'";

$result = mysql_query($select);
$datum = mysql_result($result,0,'datum');
$medewerkernummer = mysql_result($result,0,'medewerkernummer');

$export = mysql_query($select);
$fields = mysql_num_fields($export);
$kop = "";
$data = "";

for ($i = 0; $i < $fields; $i++) {
$kop .= mysql_field_name($export, $i) . "\t";
}

while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);

if ($data == "") {
$data = "\n(0) Records Found!\n";
}

header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=dagrapport-$datum-$medewerkernummer.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$kop\n$data";

All the best,
Jasper

coopster

5:57 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jlenting.

So you aren't really saving it to the server but reading the data from a database, formatting a string in memory and pushing that content out with your own headers. It is a fairly common process and I see your attempt here, but what exactly is the problem?