Guest User

Untitled

a guest
Jul 14th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2. // Database Connection Details //
  3. $db_host = 'localhost';
  4. $db_user = 'root';
  5. $db_pass = '123abc';
  6. $db_name = 'webform';
  7.  
  8. // Database Connection //
  9. $db_connect = mysqli_connect($db_host, $db_user, $db_pass, $db_name)
  10. or die('Error connecting to the database. See datainsert.php.');
  11.  
  12. $query = "SELECT * FROM webtable";
  13.  
  14. $result = mysqli_query($db_connect, $query)
  15. or die(mysqli_error($db_connect));
  16.  
  17. $count = mysqli_num_fields($result);
  18.  
  19. for ($i = 0; $i < $count; $i++){
  20. $header .= mysqli_field_name($result, $i)."\t";
  21. }
  22.  
  23. while($row = mysqli_fetch_row($result)){
  24. $line = '';
  25. foreach($row as $value){
  26. if(!isset($value) || $value == ""){
  27. $value = "\t";
  28. }else{
  29. $value = str_replace('"', '""', $value);
  30. $value = '"' . $value . '"' . "\t";
  31. }
  32. $line .= $value;
  33. }
  34. $data .= trim($line)."\n";
  35. }
  36. $data = str_replace("\r", "", $data);
  37.  
  38. if ($data == "") {
  39. $data = "\no matching records found on the table\n";
  40. }
  41. header("Content-type: application/octet-stream");
  42. header("Content-Disposition: attachment; filename=webform_excel_report.xls");
  43. header("Pragma: no-cache");
  44. header("Expires: 0");
  45.  
  46. echo $header."\n".$data;
  47. ?>
Add Comment
Please, Sign In to add comment