Advertisement
Guest User

Untitled

a guest
Jun 29th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. //THIS FILE JUST CONTAINS THE DB CONNECTION AND THATS IT
  4. include_once "config.php";
  5.  
  6. $table = 'patients'; // table you want to export
  7. $file = 'IME_Session'; // csv name.
  8.  
  9.  
  10. $result = mysql_query("SHOW COLUMNS FROM ".$table."");
  11. $i = 0;
  12.  
  13. if (mysql_num_rows($result) > 0) {
  14. while ($row = mysql_fetch_assoc($result)) {
  15. $csv_output1 .= $row['Field'].";";
  16. $i++;}
  17. }
  18. $csv_output1 .= "\n";
  19. $values = mysql_query("SELECT * FROM ".$table."");
  20.  
  21. while ($rowr = mysql_fetch_row($values)) {
  22. for ($j=0;$j<$i;$j++) {
  23. $csv_output2 .= $rowr[$j]."; ";
  24. }
  25. $csv_output2 .= "\n";
  26. }
  27.  
  28. $filename = $file."_".date("d-m-Y_H-i",time());
  29.  
  30. //THIS IS THE LINE THAT GIVES TROUBLE THAT DOESN'T LET ME DOWNLOAD THE CSV
  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.  
  35. print $csv_output1;
  36. print "<br>";
  37. print $csv_output2;
  38. exit;
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement