Page 1 of 1

Need help exporting data to csv file using php and smarty

Posted: Tue Dec 01, 2009 12:49 pm
by anksrulz
Hi,

I am working on a website that uses php with smarty templates and oracle as db.
I have to export data from an query to a csv file with a click on the link posted at the website.
the code works for one time but when i generate the next csv without logging out of the website it brings out the previous result, i have tried ftruncate and ifexists but to no use.
any suggestions ??

i implemented the following code:

Template file:
{foreach name=list item=order from=$tickets}
{if $smarty.foreach.list.first}
<p><a href="abc.csv">Export to CSV</a></p>{/if}

.php file:
$list = array('CASEID,PRODUCTID,PLATFORM,TIMESTAMP,NAME,AFFILIATION');
$fname= "abc.csv";

$file = fopen($fname,"w");
//ftruncate($file,0);
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
//$count = 0;
foreach($content["tickets"] as $value)
{
$list = "".$value[CASEID].",".$value[PRODUCTID].",".$value[PLATFORM].",".$value[TIMESTAMP].",".$value[NAME].",".$value[AFFILIATION];
fputcsv($file, split(',',$list));
//$count++;
}
fclose($file);
?>


However.

Re: Need help exporting data to csv file using php and smarty

Posted: Tue Dec 01, 2009 12:50 pm
by anksrulz
the php code again :

$list = array('CASEID,PRODUCTID,PLATFORM,TIMESTAMP,NAME,AFFILIATION');

$fname= "abc.csv";

$file = fopen($fname,"w");
//ftruncate($file,0);
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
//$count = 0;
foreach($content["tickets"] as $value)
{
$list = "".$value[CASEID].",".$value[PRODUCTID].",".$value[PLATFORM].",".$value[TIMESTAMP].",".$value[NAME].",".$value[AFFILIATION];
fputcsv($file, split(',',$list));
//$count++;
}
fclose($file);
?>

Re: Need help exporting data to csv file using php and smarty

Posted: Tue Dec 01, 2009 2:59 pm
by anksrulz
Well,

I tested a few more methods but I have not been able to get the new data yet.

The problem here is that if i do not log out and click the link it gives the same csv from the previous query. However, if i leave the page open and come back and try after say half an hour i get the new query results.

I need to fix this but i am not sure what is causing the delay.

Somebody help !!