By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

export data to xls format

P: 56
Dear Sir,
Can you tell me how to export data from MySQL database to a xls file using php code?I have to export data from different tables of mysql database to a single xls file.Please help me!!!

Regards,
Sejal Mandaliya
Dec 12 '07 #1
Share this Question
Share on Google+
4 Replies


zabsmarty
P: 25
Hello Sejal Mandaliya,
I send you the script that make your work easy....

Reply me hows its worked.


Regards
zabsmarty


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. //include db connection file
  4.  
  5. include 'connection.php';
  6.  
  7. $query = "SELECT first_name, last_name, preferred_name, nick_name, ethnicity, gender, email, mobile, phone, line_1,line_2, subrub, city,country, graduating_university, year_graduation, level_training, level_training_year, hospital_main, vocational_interest_1 FROM members ";
  8.  
  9. $result = mysql_query($query) or die('Error, query failed');
  10.  
  11. $tsv = array();
  12. $html = array();
  13. while($row = mysql_fetch_array($result, MYSQL_NUM))
  14. {
  15.     $tsv[]  = implode("\t", $row);
  16.     $html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
  17. }
  18.  
  19. $tsv  = implode("\r\n", $tsv);
  20. $html = "<table>" . implode("\r\n", $html) . "</table>";
  21.  
  22. $fileName = date("d-m-Y").'_mysql.xls';
  23. header("Content-type: application/vnd.ms-excel"); 
  24. header("Content-Disposition: attachment; filename=$fileName");
  25.  
  26. //echo $tsv;
  27. echo $html;
  28.  
  29. //include 'library/closedb.php';
  30. header('location:thanks.php');
  31. ?>
  32.  
  33.  
  34.  


Dear Sir,
Can you tell me how to export data from MySQL database to a xls file using php code?I have to export data from different tables of mysql database to a single xls file.Please help me!!!

Regards,
Sejal Mandaliya
Dec 12 '07 #2

P: 56
Thanks,
Thank you very very much.Your code is working properly.But the lines are not enalbed in xls file.Data is displayed properly but the lines are not enabled in xls file.
Dec 13 '07 #3

zabsmarty
P: 25
Thanks to reply, and no problem for thanks, Sejal i does not understand this problem please clarify me so i make to solve this problem for you. reply me soon.

Ragards
zabmsarty



Thanks,
Thank you very very much.Your code is working properly.But the lines are not enalbed in xls file.Data is displayed properly but the lines are not enabled in xls file.
Dec 15 '07 #4

pbmods
Expert 5K+
P: 5,821
Heya, Sejal.

Check out the Spreadsheet_Excel_Writer class.
Dec 23 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.