In this Tutorial, We are going to show you how to export data into CSV file using PHP and Functions. Just create a table with following fields written below and insert data into it. But note here that we have created one date field with date set value.
In this, we have connect database and hostname with server in the beginning and then use the following query for retrieve data and write into the CSV file using PHP function. you can use this script into your live projects. its very important in larger project.
If you are familiar with PHP and its function then you can easily use this script according to your need.
Don't forget to send feedback or comment in post.
Thanks, Happy Coding.
In this, we have connect database and hostname with server in the beginning and then use the following query for retrieve data and write into the CSV file using PHP function. you can use this script into your live projects. its very important in larger project.
If you are familiar with PHP and its function then you can easily use this script according to your need.
");
// These are the fields of database table from where we are retrieving data.
$myArr = "#, Transaction No, CAFID, MOBILE, COUNTRY GROUP, AMOUNT, RECEIPT NO, REQUEST DATE, STATUS, EXECUTIVE NAME, REMARKS"."\n";
if($_REQUEST['code']==1)
{
$nums = 1;
$query = mysql_query("SELECT * from #_receipt ORDER BY pid DESC;");
while ($line = mysql_fetch_array($query))
{
$myArr .= $nums.",";
$myArr .= $line['$Transaction'].",";
$myArr .= $line['$CAFID'].",";
$myArr .= $line['$MOBILE'].",";
$myArr .= $line['$COUNTRY'].",";
$myArr .= $line['$AMOUNT'].",";
$myArr .= $line['$RECEIPT'].",";
$myArr .= date("d-m-Y", $line['$REQUEST']).",";
$myArr .= $line['$STATUS'].",";
$myArr .= $line['$EXECUTIVE'].",";
$myArr .= $line['$REMARKS'].","."\n";
$nums++;
}
$fname = "Recharge_".time().'_report.csv';
$fp = fopen($fname,'w');
fwrite($fp,$myArr);
fclose($fp);
// used header for downloading file or download option from browser.
header('Content-type: application/csv');
header("Content-Disposition: inline; filename=".$fname);
readfile($fname);
unlink($fname);
}
?>
If still you have any query or problem regarding this Export data into the .CSV file then feel fre to contact us as soon as possible. we will contact and help you regarding the same.Don't forget to send feedback or comment in post.
Thanks, Happy Coding.
0 comments:
Post a Comment