Download data and column headers
Posted: Thu Aug 03, 2006 11:40 am
Hi the code below prints all my backend data on the screen I then view the page source and save the source as csv. giving me an excel spreadsheet with all my data, PERFECT!!!
BUT can I adjust this code to also download the colum headers as well as the data.
Reason is that some of the data is a simple yes/no value it would be good to know which column the Yes is reffering too, names, dates and other data are easy to recognise but yes/no values needa column header when downloaded.
So as I said above is there anyway to download column header/name as well as data using my method?
Code is below:
BUT can I adjust this code to also download the colum headers as well as the data.
Reason is that some of the data is a simple yes/no value it would be good to know which column the Yes is reffering too, names, dates and other data are easy to recognise but yes/no values needa column header when downloaded.
So as I said above is there anyway to download column header/name as well as data using my method?
Code is below:
Code: Select all
<?php
header ("Content-type: text/csv");
/* Connecting, selecting database */
$link = mysql_connect("xxx", "xxx", "xxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$query = "SELECT * FROM feedbackcontacts ORDER BY surname";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
printf ("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
$line['salutation'],$line['name'],$line['surname'],
$line['address'],$line['address1'],$line['telephonefax'],
$line['mobile'],$line['mscints'],$line['mscactive'],
$line['otheractivites'],$line['gradjobs'],$line['ugproj'],
$line['pdev'],$line['bcsmem'],$line['bcspds'],
$line['teach'],$line['accconsult']
);
?>