close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Add Row to Recordset results to use in CSV Header?

Thread began 2/01/2019 12:07 pm by Steve | Last modified 2/01/2019 2:43 pm by Steve | 343 views | 4 replies

Steve

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?

php:
// 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);

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...