Jump to content

problem exporting php data to excel file.


marina_darkfury

Recommended Posts

Hi, this is my first time here.

 

i am trying to create an xls file from the data i get from mysql. here is the code i tried but i am not able to use it correctly.

ob_start();
include('config');
$datacat = mysql_query("SELECT *
FROM `leads`") or die(mysql_error());
$name = mysql_fetch_assoc($datacat);

$line1="Industry,Company Name,Officials Name,Job Title,Country,Direct Number Mobile Number,Switch Board Number,E-mail,Executive NamePitch Date,Call Back Date,Comments\t";
while($row = mysql_fetch_array($datacat, MYSQL_ASSOC)) {
$line2= $name['industry'].",".$name['company_name'].",".$name['officials_name'].",".$name['job_title'].",".$name['country'].",".$name['direct_number_mobile_number'].",".$name['switch_board_number'].",".$name['email'].",".$name['executive_name'].",".$name['pitch_date'].",".$name['call_back_date'].",".$name['comment']."\t"."\n";
}
$data="$line1\n$line2\n";

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

 

i get my webpage title in the top of xls file and all the fields in xls file are separated by commas, whereas i want them to be in proper tables.

 

Help would be much appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.