<?php
session_start();
// $filename = "Report_" . date('MmDY') . ".xls";
// header("Content-type: application/octet-stream");
// header("Content-Disposition: attachment; filename=\"$filename\"");
// header("Pragma: no-cache");
// header("Expires: 0");
include ('../connection.php');
include ('../libchart/classes/libchart.php');
$calendarDate1 = $_SESSION['dateCalendarONE'];
$calendarDate2 = $_SESSION['dateCalendarTWO'];
$inputValue = $_SESSION['menuInputVALUE'];
$sql = ("
SELECT *
FROM `tally`, `category`
WHERE tally.catid = category.catid AND
date BETWEEN '" . $calendarDate1 . "' AND '" . $calendarDate2 . "'
AND CATLABEL='" . $inputValue . "'
GROUP BY `catlabel`
");
$rec = mysql_query($sql) or die (mysql_error());
$num_fields = mysql_num_fields($rec);
//loop count
for($i = 0; $i < $num_fields; $i++ )
{
$header .= mysql_field_name($rec,$i)."\t";
}
//Oraganize information on the database.
while($row = mysql_fetch_assoc($rec))
{
$line = '';
foreach($row as $brotocol)
{
if((!isset($brotocol)) || ($brotocol == ""))
{
$brotocol = "\t";
}
else
{
$brotocol = str_replace( '"' , '""' , $brotocol );
$brotocol = '"' . $brotocol . '"' . "\t";
}
$line .= $brotocol;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace("\r" , "" , $data);
if ($data == "")
{
$data = "\n BROTOCOL_ERROR: contact support!!!\n";
}
print "$header\n$data";
?>
传递会话变量时,excel 的导出不会循环并仅读取 1 行。但是当 sql 语句被硬编码时,它会根据需要循环遍历尽可能多的行。循环算法有错误吗?还是我必须在代码中添加另一个while循环?