Jump to content

CSV file not showing the db results properly


confused_aswell

Recommended Posts

Hi

 

I am using this script to show the database results, everything shows except the phone numbers. The first 2 show correctly then the 3rd has the zero missing from the start of the number the 4th is ok then the next one didn't enter his number so this just shows as a 0 then the next 4 have the zero missing again, the one after that is fine then another 2 with the missing zero and then all of the numbers after that are fine. A bit of an odd one, I don't think it could be the script - could it?

 

Any help would be appreciated.

 

Thanks,

 

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' => '', 
'entry_company' => 'Customer Name',
   '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'
); 

$values = mysql_query("SELECT
a.entry_company, a.entry_firstname, a.entry_lastname, a.entry_street_address,
a.entry_suburb, a.entry_city, a.entry_postcode, c.customers_email_address, c.customers_telephone
FROM
zen_address_book as a
LEFT JOIN
zen_customers as c
ON
c.customers_id = a.customers_id 


");
$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;


Hi

 

Thanks very much. I have just realised that the incorrect numbers were all one long string of numbers. So to your answer, could you tell me where exactly to put your answer in my code as I am not phpfreak - just a newbie!

 

Thanks,

 

Phil

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.