Guest User

Untitled

a guest
Feb 28th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. $username="root"; $password=""; $database="exam_codes";
  3. $con = mysql_connect("localhost",$username,$password) or die( "Unable to Connect database");
  4. mysql_select_db($database,$con) or die( "Unable to select database");
  5. // Table Name that you want
  6. // to export in csv
  7. $ShowTable = "blogs";
  8.  
  9. $FileName = "_export.csv";
  10. $file = fopen($FileName,"w");
  11.  
  12. $sql = mysql_query("SELECT * FROM `$ShowTable` LIMIT 11");
  13. $row = mysql_fetch_assoc($sql);
  14. // Save headings alon
  15. $HeadingsArray=array();
  16. foreach($row as $name => $value){
  17. $HeadingsArray[]=$name;
  18. }
  19. fputcsv($file,$HeadingsArray);
  20.  
  21. // Save all records without headings
  22.  
  23. while($row = mysql_fetch_assoc($sql)){
  24. $valuesArray=array();
  25. foreach($row as $name => $value){
  26. $valuesArray[]=$value;
  27. }
  28. fputcsv($file,$valuesArray);
  29. }
  30. fclose($file);
  31.  
  32. header("Location: $FileName");
  33.  
  34. echo "Complete Record saves as CSV in file: <b style=\"color:red;\">$FileName</b>";
  35. ?>
Add Comment
Please, Sign In to add comment