<?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 ) . "
";
}
$data = str_replace("" , "" , $data);
if ($data == "")
{
$data = "
BROTOCOL_ERROR: contact support!!!
";
}
print "$header
$data";
?>
When the session variable is passed, the exporting for excel is not looping through the and only reading 1 row. but When the sql statement is hard-coded in, it loops through as many rows as needed. Is the error with the loop alogrithm? or do I have to add another while loop in the code?