944,192 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2033
  • PHP RSS
Oct 11th, 2007
0

Mysql to Excel worksheet, need code

Expand Post »
Is it possible to copy a mysql database to an excel worksheet writting PHP code..

please help with code.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rime is offline Offline
24 posts
since Aug 2007
Oct 11th, 2007
0

Re: Mysql to Excel worksheet, need code

Please read my article on exporting to Excel in PHP here.
Let me know if that helps. You can read lot of other articles on that site too.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Oct 12th, 2007
0

Re: Mysql to Excel worksheet, need code

yes I have read your article and its helpful.. thans a lot
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rime is offline Offline
24 posts
since Aug 2007
Oct 12th, 2007
0

Re: Mysql to Excel worksheet, need code

ok, Glad I was able to help. You can post your queries in the "Ask an Expert" section also.
Last edited by binoj_daniel; Oct 12th, 2007 at 1:39 pm.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006
Jan 3rd, 2011
0
Re: Mysql to Excel worksheet, need code
check this code mysql to excel

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. ob_start("ob_gzhandler");
  3. include("../config/dbconfig.php");
  4. $result = mysql_query('select * from ra_salesreport');
  5. $count = mysql_num_fields($result);
  6. for ($i = 0; $i < $count; $i++){
  7. $header .= mysql_field_name($result, $i)."\t";
  8. }
  9. while($row = mysql_fetch_row($result)){
  10. $line = '';
  11. foreach($row as $value){
  12. if(!isset($value) || $value == ""){
  13. $value = "\t";
  14. }else{
  15. $value = str_replace('', '', $value);
  16. $value = '' . $value . '' . "\t";
  17. }
  18. $line .= $value;
  19. }
  20. $data .= trim($line)."\n";
  21. }
  22. $data = str_replace("\r", "", $data);
  23. if ($data == "") {
  24. $data = "\nno matching records found\n";
  25. }
  26. header("Content-type: application/octet-stream");
  27. header("Content-Disposition: attachment; filename=resume.xls");
  28. header("Pragma: no-cache");
  29. header("Expires: 0");
  30. echo $header."\n".$data;
  31. ?>
Last edited by Ezzaral; Jan 3rd, 2011 at 12:50 pm. Reason: Added code tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rahulb310 is offline Offline
3 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Upcoming Events script (Free or Commercial)...?
Next Thread in PHP Forum Timeline: Parse error: syntax error, unexpected T_STRING





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC