Download Function
Posted: Wed Jul 19, 2006 4:59 am
I tried to attemt this about a year ago but never got anywhere, Im going to give it another go and would really appreciate the help.
Basically I have a system which displays records from my database, my team want to be able to download this data into an excel spreadsheet to use it as a source for mailouts.
I want to create a button on all my screens called download.
This button when selected will down load all the 'backend' data from the page being viewed and export it.
Now when I tried this previously I came up with something like this:
Download button pointed to the current page url/export_csv.php
the code for this link is:
But all this does is print a load of data on the screen.
Any help or advice would be greatly appreciated.
Also there doesnt seem to be much information on this, I thought it would be a really common procedure for people to download there data for mailouts??
Basically I have a system which displays records from my database, my team want to be able to download this data into an excel spreadsheet to use it as a source for mailouts.
I want to create a button on all my screens called download.
This button when selected will down load all the 'backend' data from the page being viewed and export it.
Now when I tried this previously I came up with something like this:
Download button pointed to the current page url/export_csv.php
the code for this link is:
Code: Select all
<?php
header ("Content-type: text/csv");
/* Connecting, selecting database */
$link = mysql_connect("xxxxx", "xxxx", "xxxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$query = "SELECT * FROM people ORDER BY organisation";
$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,%s\n",
$line['person_id'],$line['salutation'],$line['firstname'],
$line['surname'],$line['organisation'],$line['role'],
$line['address1'],$line['address2'],$line['city'],$line['postcode'],
$line['telephone'],$line['mobile'],$line['fax'],
$line['dateoflastcontact'],$line['datecontactagain'],
$line['notes'],$line['email'],$line['org_id']
);
?>But all this does is print a load of data on the screen.
Any help or advice would be greatly appreciated.
Also there doesnt seem to be much information on this, I thought it would be a really common procedure for people to download there data for mailouts??