PHP Outputting to CSV

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi All

I have a table in my database full of addresses and I need to output it to a CSV file. I cant get it to work though.

Here is my code so far. Can anyone suggest whats wrong?

Code:
<?
require_once('Connections/wp_data.php'); 
mysql_select_db($database_wp_data, $wp_data);
//$csv_output = '"column 1","column2"';
$csv_output = "\015\012";
$result = mysql_query("select * from addresses");

  while($row = mysql_fetch_array($result)) {
    $csv_output .= ''.$row[field1].','.$row[field3].','.$row[field6].','.$row[field7].','.$row[field8].','.$row[field9].','.$row[field10].','.$row[field11].','.$row[field13].','.$row[field14].','.$row[field5].',';
   $csv_output .= "\015\012";
  }


  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv; filename=parcel_force_address_list_" . date("Ymd") .".csv");
  print $csv_output;
  exit;
?>

thanks
Aaron
 
Its complicated lol.

The contents of the csv are constantly changing, thanks Ebay ;) So I don't name them. they are just field1,2 etc and then I have a piece of paper with what is what

Anyhoo, I solved this now anyway :)

Aaron
 
Back
Top Bottom