Downloading Data
Moderator: General Moderators
Downloading Data
Ok, I want my users to run a mailmerge from the data they view on the web application.
the best way to do this is to allow them to download the data and then they can just use excell and word to do the mail merge.
Im having problems with how to go about dowloading data, I was told that the 'trick is to create a link to the website adding '\download' to the url or something like this.
anyone got any advice
the best way to do this is to allow them to download the data and then they can just use excell and word to do the mail merge.
Im having problems with how to go about dowloading data, I was told that the 'trick is to create a link to the website adding '\download' to the url or something like this.
anyone got any advice
sorry pimpster posted the question on the wrong forum - I wanted to see what the guys on 'sitepoint' had to say about it.
Im now going back to the advice that you guys gave - only problem was that last time loads of people chipped in and gave so many conflicting views on what was the easiest way that I got confused, ive now decided im gonna do it your way - using the export_csv method and and then linkinkg to the download page.
Cheers
Im now going back to the advice that you guys gave - only problem was that last time loads of people chipped in and gave so many conflicting views on what was the easiest way that I got confused, ive now decided im gonna do it your way - using the export_csv method and and then linkinkg to the download page.
Cheers
Mark This is what Ive tried
Ive created a file called export_csv.php
heres the code for that file:
Ok I have then created a link on my view 'People' Page that reads like this:
any ideas as to whats going wrong??
Ive created a file called export_csv.php
heres the code for that file:
Code: Select all
<?php
/* Connecting, selecting database */
$link = mysql_connect("xxxxx", "xxx", "xxxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
Header ("Content-type: text/csv");
//This is my code, change your queries and formatting
$query = "SELECT * FROM people ORDER BY organisation";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "".$line['person_id'].",".$line['salutation'].",".$line['firstname'].",
".$line['surname'].",".$line['organisation'].",".$line['role'].",
".$line['address1'].",".$line['address2'].",".$line['city'].",".['postcode'].",
".$line['telephone'].",".$line['mobile'].",".$line['fax'].",
".$line['dateoflastcontact'].","$line.['datecontactagain'].",
".$line['notes'].",".$line['email'].",".$line['org_id']."\n";
}
?>when I click on the link all that happens that the browsers searchs for the site then states 'done' in the bottom corner all I am left with is a blank white screen.<a href=http://editweb.soi.city.ac.uk/organisat ... export.csv> Dowload<a/>
any ideas as to whats going wrong??
put
At the very top of the script...first line
Code: Select all
Header ("Content-type: text/csv");did it and the same thing happens???
Code: Select all
<?php
Header ("Content-type: text/csv");
/* Connecting, selecting database */
$link = mysql_connect("xxxx", "xxx", "xxxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
//This is my code, change your queries and formatting
$query = "SELECT * FROM people ORDER BY organisation";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "".$line['person_id'].",".$line['salutation'].",".$line['firstname'].",
".$line['surname'].",".$line['organisation'].",".$line['role'].",
".$line['address1'].",".$line['address2'].",".$line['city'].",".['postcode'].",
".$line['telephone'].",".$line['mobile'].",".$line['fax'].",
".$line['dateoflastcontact'].","$line.['datecontactagain'].",
".$line['notes'].",".$line['email'].",".$line['org_id']."\n";
}
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Ive also tried this but again the page loads with a blank screen and nothing downloads - am I missing something here or should something happen when I get to the export_csv link.
Code: Select all
<?php
header ("Content-type: text/csv");
/* Connecting, selecting database */
$link = mysql_connect("xxxx", "xxx", "xxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
//This is my code, change your queries and formatting
$query = "SELECT * FROM people ORDER BY organisation";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "".$line['person_id'].",".$line['salutation'].",".$line['firstname'].",
".$line['surname'].",".$line['organisation'].",".$line['role'].",
".$line['address1'].",".$line['address2'].",".$line['city'].",".['postcode'].",
".$line['telephone'].",".$line['mobile'].",".$line['fax'].",
".$line['dateoflastcontact'].","$line.['datecontactagain'].",
".$line['notes'].",".$line['email'].",".$line['org_id']."\n";
}
?>this is the exact code i am currently using
Code: Select all
<?php
header ("Content-type: text/csv");
$BasePath = str_repeat("../", substr_count(dirname($_SERVER["SCRIPT_NAME"]), "/"));
require ($BasePath."ocdaintranet/includes/db_connection.php");
$query = "SELECT * FROM contacts ORDER BY company";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "".$line['id'].",".$line['company'].",".$line['name'].",".$line['position'].",".$line['address'].",".$line['notes'].",".$line['tel'].",".$line['direct_line'].",".$line['fax'].",".$line['mobile'].",".$line['email'].",".$line['web']."\n";
}
?>Ive had a look over my downloading data code and ive finally got it to work im experiencing one problem though all the data is currently being printed on screen - I was told by a technical expert that I need to change the header code to one which opens a file save box rather than print the raw data on screen - can someone help with regards to the correct header information.
the working code is below:
the working code is below:
Code: Select all
<?php
header ("Content-type: text/csv");
/* Connecting, selecting database */
$link = mysql_connect("xxxx", "xxx", "xxxx")
or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");
//This is my code, change your queries and formatting
$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']
);
?>