Add Row to Recordset results to use in CSV Header?
How can I add a row to a recordsets results to use as a CVS header?
I'm successfully writing a CSV file but there is no Header values. It's easy to generate these in PhpMyAdmin as an exported csv file.
The code below takes the results from $Recordset1 and puts them in an array ($DataArray). But it is overwriting the list of column names.
How can I manually push the row of column names into the 1st position of the array to use as CSV Header values?
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=all-entries.csv');
// output the column headings
$DataArray = array('invTitle','invDescr','Address','City','fid','key','FeatRoofType','FeatSidingType','FeatColor','FeatGarage','FeatCarport','FeatStorShed','FeatGutters','FeatShutters','FeatThermoWindw','FeatDeck','FeatPatio','FeatCeilings','FeatIntWalls','FeatHeating','FeatIntCAir','FeatIntWAir','FeatIntFirePl','FeatIntPantry','FeatIntSkyLight','FeatIntCFan','FeatIntCathC','FeatIntSunRoom','FeatIntGTub','FeatIntBasement','FeatIntWalkInCloset','FeatIntLaundry','FeatApplDishw','FeatApplDryer','FeatApplWasher','FeatApplGarbageD','FeatApplOven','FeatApplMicroW','FeatApplRefridge');
$DataArray = $Recordset1->Results; // puts results into array
// create a file pointer (FP) connected to the output stream
$fp = fopen('php://output', 'w');
foreach ($DataArray as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);