forget all use one of those :
[php]
$filename="exce l.xls";
$sql = "xxxx";
$result = mysql_query($sq l);
while($line = mysql_fetch_ass oc($result))
{
if(empty($cols) )
{
$data .= implode("\t", array_keys($lin e))."\r\n";
$cols = true;
}
$data .= implode("\t",$l ine)."\r\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filen ame");
header("Pragma: no-cache");
header("Expires : 0");
print "$data";
[/php]or this one if you want to create file [php]
<?php
$filename = "excel-m.xls";
$sql = "xxxxxxxx";
$result = mysql_query($sq l);
if(file_exists( 4filename)unlin k($filename);
$fp = fopen($filename ,'w');
$result = mysql_query($sq l);
while($line = mysql_fetch_ass oc($result))
{
if(empty($cols) )
{
fwrite($fp,impl ode("\t", array_keys($lin e))."\r\n");
$cols = true;
}
fwrite($fp,impl ode("\t",$line) ."\r\n");
}
fclose($fp);
header("Locatio n: $filename"); //coment it if you dont want to redirect
?>
[/php]
first one is great to generate dynamically
second if you want to print to file and use it later
regards
jx2
[php]
$filename="exce l.xls";
$sql = "xxxx";
$result = mysql_query($sq l);
while($line = mysql_fetch_ass oc($result))
{
if(empty($cols) )
{
$data .= implode("\t", array_keys($lin e))."\r\n";
$cols = true;
}
$data .= implode("\t",$l ine)."\r\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filen ame");
header("Pragma: no-cache");
header("Expires : 0");
print "$data";
[/php]or this one if you want to create file [php]
<?php
$filename = "excel-m.xls";
$sql = "xxxxxxxx";
$result = mysql_query($sq l);
if(file_exists( 4filename)unlin k($filename);
$fp = fopen($filename ,'w');
$result = mysql_query($sq l);
while($line = mysql_fetch_ass oc($result))
{
if(empty($cols) )
{
fwrite($fp,impl ode("\t", array_keys($lin e))."\r\n");
$cols = true;
}
fwrite($fp,impl ode("\t",$line) ."\r\n");
}
fclose($fp);
header("Locatio n: $filename"); //coment it if you dont want to redirect
?>
[/php]
first one is great to generate dynamically
second if you want to print to file and use it later
regards
jx2
Comment