CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 generate csv

Print topic Send  topic

Author Message
manuel

Posts: 48
Posted: 05/27/2013, 3:28 PM

I need to generate a csv file, and the name of the file must be Report_yymmdd.csv

this most be done automatically, the user must click a link and the file will be automatically generated.

I've found some examples of how to generate a csv from php, but someone has done this from within CCS?
View profile  Send private message
MichaelMcDonald

Posts: 639
Posted: 05/28/2013, 6:03 AM

My thanks to whoever posted this, when I find it again I will credit you, in the meantime....reposting:


This goes in your _events.php file:

$sql =".....
$db->query($sql);


exportMysqlToCsv($sql,'Order_Report('.date(dMYHis).').csv');
}




Put this function in the bottom of common.php:


function exportMysqlToCsv($sql,$filename = 'export.csv')
{
$maxrecordscsv = 10000;


$db=new clsDBFM();
$sql_exec = $db->query($sql.' LIMIT 0, 1');
$cols = @array_keys(@mysql_fetch_assoc($sql_exec));
$table = @implode(',',$cols)."\n";
$count_col = count($cols);
$sql_exec = $db->query($sql. " LIMIT 0, $maxrecordscsv");
while ($db->next_record())
{
$col_array = NULL;
for($i = 0 ; $i < $count_col ; $i++)
{
$col_array[] = $db->f($cols[$i]);
}
$table .= @implode(',',$col_array)."\n";
}

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($table));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");


echo $table;
exit;

}
_________________
Central Coast, NSW, Australia.

View profile  Send private message
DataDoIT
Posted: 05/28/2013, 12:20 PM

Instead of putting that whole function in the bottom of Common.php, put
the function at the bottom of your _events.php file. Or better yet,
create your own custom functions PHP file and put this at the bottom of
your Common.php:

include_once('Custom.php');

Then place your own classes and functions in that file, ultimately
building your own library.
manuel

Posts: 48
Posted: 05/28/2013, 1:41 PM

Thanks to both, I almost give up on this one.

This was one of two major obstacles I found in my project. Can you please take a look to: http://forums.yessoftware.com/posts.php?post_id=121337 also.

Really, Thank you both
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.