I created a csv file fine but when i input numbers starting with zero (0) or money with .00 it does not display them. Any ideas?
The numbers below get displayed like this in excel when you open the csv:
0066789 gets displayed like 66789
0023456 gets displayed like 23456
or
144.00 gets displayed like 144
160.00 gets displayed like 160
But if i change the field type from general to integer in excel they come out fine OR if i put a space before or seperate the number like "00 66789" then the zeros display and the number comes out correct.
Is there a better way of making csv files? Plus the problem I have with the code below is that I have to open it in a new window for the windows "save" dialogue to turn up and the open window does not close after the file is saved by the user.
heres my code:
Code: Select all
<?php
ob_start();
$str .= "\"Ref.No.\",\"Account name\",\"Account No\",\"Payment 1\""."\n";
$sql_accP = "select * from tbl_accounts";
$mysql_result_accP = mysql_query($sql_accP,$conn);
$num_rows_acc = mysql_num_rows($mysql_result_accP);
while ($row3 = mysql_fetch_array($mysql_result_accP))
{
$accid = $row3["accid"];
$ac_name = $row3["ac_name"];
$ac_ref = $row3["ac_ref"];
$ac_no = $row3["ac_no"];
$ac_pay = $row3["ac_pay"];
$str .= "\"$ac_name\"" . "," . "\" $ac_ref\"" .","."\" $ac_no\"".","."\"$ac_pay\""."\n";
}
echo $str."\n";
$today = date("d_m_Y");
$filname = "$today";
header("Cache-control: private");
header("Content-Type: application/txt");
header("Content-Disposition: attachment; filename=$filname.csv");
ob_end_flush();
?>