im trying to write a coed where i have to export the contents of my database into a csv file
the exporting already works however my exported csv is having problems with numbers
for example my sql database looks like this
telephone number
+639063073755
however in the exported csv the data from the telephone number becomes like this
telephone number
6.39063E+11
the telephone number becomes an exponent
is there a way to fix this
here is my code
$sql = DB::query("SELECT * FROM table 1 order by id ASC");
$col2 = DB::query("SELECT * FROM table2 order by col_id ASC");
$rp_name = DB::queryOneField('rp_name',"SELECT * FROM report_presets where rp_id=%i",$_GET['rp_id']);
$rp_name = str_replace(" ","",$rp_name);
$line1 .= "Telephone Number";
foreach($sql as $row){
$line2 .=
str_replace(",","",$row[mobile_no]). ","
."\n";
}
$data="$line1\n$line2\n";
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=".$rp_name.".csv");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
thanks
If you are using excel to view the csv this problem may occur. Thats not the problem of your code. try formatting the column as number
The problem is in how Excel handles the contents of the CSV. Follow these instructions in order to get the desired result.
Thats because of excel cell width . can u add any character before the telephone number like " call:989898989898". Then there wont be problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.