Saturday, 28 September 2013

csv file not creating

csv file not creating

I want to create a csv file with fetched data>its creating the file but
showing only one date and also showing html of page.
CODE:
$sss=mysql_query("SELECT DATE(pdate),COUNT(*) AS mycount FROM
qchat_sessions WHERE MONTH(pdate)='09' GROUP BY DATE(pdate)");
while($rows = mysql_fetch_array($sss)){
$array = array(array($rows[0], $row[1]));
}
// open raw memory as file so no temp files needed, you might run out
of memory though
$f = fopen('php://memory', 'w');
$de=";";
// loop over the input array
foreach ($array as $line) {
// generate csv lines from the inner arrays
fputcsv($f, $line,$de );
}
// rewrind the "file" with the csv lines
fseek($f, 0);
// tell the browser it's going to be a csv file
header('Content-Type: application/csv');
// tell the browser we want to save it instead of displaying it
header('Content-Disposition: attachement; filename="stats.csv"');
// make php send the generated csv lines to the browser
fpassthru($f);
It should show data as:
2013-09-26 ; 1
2013-09-27 ; 2
But showing only 2013-09-27 ; 2
Thanks

No comments:

Post a Comment