itsover9000
itsover9000

Reputation: 611

Exporting mysql db(data with numbers) to csv

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

Upvotes: 2

Views: 2150

Answers (3)

Ravi Maniyar
Ravi Maniyar

Reputation: 667

Thats because of excel cell width . can u add any character before the telephone number like " call:989898989898". Then there wont be problem.

Upvotes: 1

heikkim
heikkim

Reputation: 2975

The problem is in how Excel handles the contents of the CSV. Follow these instructions in order to get the desired result.

Upvotes: 2

Arun Aravind
Arun Aravind

Reputation: 101

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

Upvotes: 2

Related Questions