This problem is driving me crazy!
I am exporting data from a mySQL database to a csv file. The file updates on the server just fine.
However when the user opens the CSV, the data is not correct.
Specifically, I have a field in my db that contains a number. Field type is varchar. Length is 16.
For the purpose of this example, the number in question is: 4060420013655609
When the end user opens the file in excel, they see:
4.06042E+15
When they reformat the column as "number" with no decimal places, Excel shows the value as: 4060420013655600
Excel is dropping the last digit and replacing it with a "0".
I am baffled as to what I'm doing wrong.
When writing the CSV, I'm using the following syntax:
$header="Order ID, fname, lname, email, address, address2, city, zip, billing_address, billing_address2, billing_city, billing_zip, area, phone, instructions, opt, card_type, card_no, card_exp, card_name, stamp, when, date, contribute_ed, contribute_ed_amt, contribute_tip, contribute_tip_amt,codeName,offer,productCode, rateTable, paperCode, sourceCode\n";
Next, I loop thru the database results, and write the following line for each result in my recordset:
$body.="$card_no,$card_exp,$card_name,$stamp,$when,$date,$contribute_ed,$contribute_ed_amt,$contribute_tip,$contribute_tip_amt,$codeName,$offerText - $term - $rate,$productCode, $rateTable, $paperCode, $sourceCode\n";
"card_no" is the problematic value at this point.
$card_no is simply a variable pulling a value from my recordset a few lines earlier in my code.
The specific code I'm using to write the file itself is:
$filename="/PATH_TO_MY_FILE/leads_report.csv";
$towrite=$header.$body;
$newfile= fopen($filename, "w") or die ("Couldn't create file");
@fwrite($newfile, $towrite) or die ("Couldn't write to file");
@fclose($newfile);
Can someone put me out of my misery and tell me what I'm doing wrong?