How do I test for no data in a string? I tried if !(isset($data)) and
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data .= $header;
if ($data == "") {
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?
tia,
------------
this is the function for $data
function makexcldata($xc lfields, $result){
$str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";
while($row = mysql_fetch_row ($result)) {
$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) ;
$data .= $str1;
return $data;
}
$data =="" and neither one returns the message when there are no
records found. Or is it a better idea to do the test at the query
level and not let the user get a worksheet with no records? The thing
is a user could click the button for excel output even if there are no
records on the web page, so I would think in that case they would
expect a blank worksheet anyways.
$data .= $header;
if ($data == "") {
$data = "\n(0) Records Found!\n";}
header("Content-type: application/xmsdownload");
header("Content-Disposition: attachment; filename=".
$file_name.=now ().".xls");
header("Pragma: no-cache");
header("Expires ; 0");
print "$header\n$data ";
the other question is how do I get it to print the date on the
filename in excel?
tia,
------------
this is the function for $data
function makexcldata($xc lfields, $result){
$str1 = '';
for($i=0; $i < sizeof($xclfiel ds); $i++){
$str1 .= $xclfields[$i];
$str1 .= "\t";
}
$str1 .= "\n";
while($row = mysql_fetch_row ($result)) {
$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) ;
$data .= $str1;
return $data;
}
Comment