Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2. $host = 'localhost';
  3. $user = 'root';
  4. $pass = 'root';
  5. $db = 'mysql';
  6. $table = 'help_category';
  7. $file = 'export';
  8.  
  9. $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
  10. mysql_select_db($db) or die("Can not connect.");
  11.  
  12. $result = mysql_query("SHOW COLUMNS FROM ".$table."");
  13. $i = 0;
  14. if (mysql_num_rows($result) > 0) {
  15. while ($row = mysql_fetch_assoc($result)) {
  16. $csv_output .= $row['Field']."; ";
  17. $i++;
  18. }
  19. }
  20. $csv_output .= "\n";
  21.  
  22. $values = mysql_query("SELECT * FROM ".$table."");
  23. while ($rowr = mysql_fetch_row($values)) {
  24. for ($j=0;$j<$i;$j++) {
  25. $csv_output .= $rowr[$j]."; ";
  26. }
  27. $csv_output .= "\n";
  28. }
  29.  
  30. $filename = $file."_".date("Y-m-d_H-i",time());
  31. header("Content-type: application/vnd.ms-excel");
  32. header("Content-disposition: csv" . date("Y-m-d") . ".csv");
  33. header( "Content-disposition: filename=".$filename.".csv");
  34. print $csv_output;
  35. exit;
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement