Hi
I have a small problem in that I have got a sql query that works on it's own but because of the layout of the script it won't.
The problem is, I am linking two tables to get the information and therefore I can't put use this Query.
Any ideas please,
Phil
Here is the SQL Query that I want to put into it -
SELECT zen_address_book.entry_firstname, zen_address_book.entry_lastname, zen_address_book.entry_street_address, zen_address_book.entry_suburb, zen_address_book.entry_city, zen_address_book.entry_postcode, zen_customers.customers_email_address FROM zen_address_book, zen_customers WHERE zen_customers.customers_id = zen_address_book.customers_id
Here is the script
$host = 'localhost';
$user = 'username';
$pass = 'passwoed';
$db = 'database';
$table = 'zen_address_book,zen_customers';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$replace = array(
'entry_firstname' => 'First Name',
'entry_lastname' => 'Last Name',
'entry_street_address' => 'Address',
'entry_suburb' => 'City',
'entry_state' => 'County',
'entry_postcode' => 'Post Code',
'customers_email_address' => 'Email Address'
);
$values = mysql_query("SELECT entry_firstname, entry_lastname, customers_email_address FROM ".$table."");
$i=0;
while ($rowr = mysql_fetch_assoc($values)) {
if($i==0) {
foreach(array_keys($rowr) as $title)
$csv_output .= '"'.str_replace(array_keys($replace), $replace, $title).'",';
$csv_output .= "\n";
}
foreach ($rowr as $key => $value) {
$csv_output .= '"'.$value.'",';
}
$csv_output .= "\n";
$i++;
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;