Hi
I need a bit of help with this script, because of the addresses of people are different legnths it is difficult to get everyone's address the same. EG 123 High Road London W1 4EX Could be one persons address but 123 High Street Totteridge High Wycombe, Bucks SL8 9UT could be anothers.
So, in calling those addresses from the database to be displayed in a excel file there needs some tinkering. Is it possible to check if entry_suburb has a value if not is it possible for it to filled with entry_city so that the address in the excel file has no empty boxes?
Thanks, I would appreciate any help.
Phil
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$replace = array(
'address_book_id' => '',
'customers_name' => 'Customer Job',
'entry_firstname' => 'First Name',
'entry_lastname' => 'Last Name',
'entry_street_address' => 'Billing Address1',
'entry_suburb' => 'Billing Address2',
'entry_city' => 'Billing Address3',
'entry_state' => 'Billing Address4',
'entry_postcode' => 'Billing Address5',
'customers_email_address' => 'Email',
'customers_telephone' => 'Phone'
);
function split_num($num){
$num = substr($num, 0, 5) . ' ' . substr($num, 5);
return $num;
}
$values = mysql_query("SELECT zen_orders.customers_name, 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_state, zen_address_book.entry_postcode, zen_orders.customers_telephone, zen_orders.customers_email_address
FROM (zen_address_book INNER JOIN zen_orders ON zen_address_book.customers_id = zen_orders.customers_id) INNER JOIN zen_customers ON (zen_address_book.address_book_id = zen_customers.customers_default_address_id) AND (zen_address_book.customers_id = zen_customers.customers_id)
");
$i=0;
while ($rowr = mysql_fetch_assoc($values)) {
if(!preg_match('#\x20#', $rowr['customers_telephone'], $match)){ // does not find a space...
$rowr['customers_telephone'] = split_num($rowr['customers_telephone']);
}
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;