Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <?php
  2.  
  3. /* Define our Database and Table Info */
  4.  
  5.  
  6. $username="";
  7. $password="";
  8. $database="";
  9. $table="";
  10.  
  11.  
  12. mysql_connect(localhost,$username,$password);
  13. @mysql_select_db($database) or die( "Unable to select database");
  14. $select = "SELECT * FROM $table";
  15. $export = mysql_query($select);
  16. $fields = mysql_num_fields($export);
  17.  
  18. for ($i = 0; $i < $fields; $i++) {
  19. $header .= mysql_field_name($export, $i) . "t";
  20. }
  21.  
  22. while($row = mysql_fetch_row($export)) {
  23. $line = '';
  24. foreach($row as $value) {
  25. if ((!isset($value)) OR ($value == "")) {
  26. $value = "t";
  27. } else {
  28. $value = str_replace('"', '""', $value);
  29. $value = '"' . $value . '"' . "t";
  30. }
  31. $line .= $value;
  32. }
  33. $data .= trim($line)."n";
  34. }
  35. $data = str_replace("r","",$data);
  36.  
  37. if ($data == "") {
  38. $data = "n(0) Records Found!n";
  39. }
  40.  
  41. header("Content-type: application/x-msdownload");
  42. header("Content-Disposition: attachment; filename=mailinglist.xls");
  43. header("Pragma: no-cache");
  44. header("Expires: 0");
  45. print "$headern$data";
  46. ?>
  47.  
  48. <?php
  49.  
  50. / Define our Database and Table Info /
  51.  
  52. $username="";
  53. $password="";
  54. $database="";
  55. $table="";
  56.  
  57. mysql_connect(localhost,$username,$password);
  58. @mysql_select_db($database) or die( "Unable to select database");
  59. $select = "SELECT * FROM $table";
  60. $export = mysql_query($select);
  61. $fields = mysql_num_fields($export);
  62.  
  63. for ($i = 0; $i < $fields; $i++) {
  64. $header .= mysql_field_name($export, $i) . ",";
  65. }
  66.  
  67. while($row = mysql_fetch_row($export)) {
  68. $line = '';
  69. foreach($row as $value) {
  70. if ((!isset($value)) OR ($value == "")) {
  71. $value = ",";
  72. } else {
  73. $value = str_replace('"', '""', $value);
  74. $value = '"' . $value . '"' . ",";
  75. }
  76. $line .= $value;
  77. }
  78. $data .= trim($line)."n";
  79. }
  80. $data = str_replace("r","",$data);
  81.  
  82. if ($data == "") {
  83. $data = "n(0) Records Found!n";
  84. }
  85.  
  86. header("Content-type: application/x-msdownload");
  87. header("Content-Disposition: attachment; filename=mailinglist.xls");
  88. header("Pragma: no-cache");
  89. header("Expires: 0");
  90. print "$headern$data";
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement