//==============================
//Run the Export to a file here: I have already created code that I use for reporting that grabs the data from the existing TaxCustomers table, processes it and updates it in a temporary table. I know this process works, because I haven't changed it except for the initial SQL statement for what records it selects AND I see the temporary table get created in myPHPAdmin and it contains the updated data. (see Topic: https://forums.nubuilder.cloud/viewtopic.php?f=20&t=10866) for reference. So by the time the PHP script reaches this export section the records exist in a Temporary table and that table name is in the variable $tabid.
//==============================
Code: Select all
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=ExpTaxCustomers.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings of my table
fputcsv($output, array('TaxCustomers_id', 'cust_prissn', 'cust_retdate', 'cust_lastname', 'cust_firstname', 'cust_midinit', 'cust_surname', 'cust_spouse', 'tax_office', 'tax_comments', 'count'));
// fetch the data from the temporary table $tabid - I know this table exists and has the correct data in it. I checked my nudebug to make sure its using the correct table name.
$expsql = "SELECT * From $tabid";
nuDebug($expsql);
$t = nuRunQuery($expsql);
// loop over the rows, outputting them this should output the rows to the output device.
while($r = db_fetch_array($t)){
fputcsv($output, $r);
} //end While Loop