Can anyone help with this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Can anyone help with this

Post by mohson »

mohson wrote: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:

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']
	);

 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look at the header() documentation, we've also talk a lot about forcing a download. :roll:

http://php.net/function.header
Post Reply