Guest User

Untitled

a guest
Oct 3rd, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. /*******EDIT LINES 3-8*******/
  3.  
  4. $DB_Server = "localhost"; //MySQL Server
  5. $DB_Username = "pcomp"; //MySQL Username
  6. $DB_Password = "contraseña"; //MySQL Password
  7. $DB_DBName = "BBDD"; //MySQL Database Name
  8. $DB_TBLName = "alertas"; //MySQL Table Name
  9. $filename = "alertas"; //File Name
  10. /*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/
  11. //create MySQL connection
  12.  
  13. $sql = "SELECT * FROM reporte";
  14.  
  15. $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
  16. //select database
  17. $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
  18. //execute query
  19. $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
  20. $file_ending = "xls";
  21. //header info for browser
  22. header("Content-Type: application/xls");
  23. header("Content-Disposition: attachment; filename=$filename.xls");
  24. header("Pragma: no-cache");
  25. header("Expires: 0");
  26. /*******Start of Formatting for Excel*******/
  27. //define separator (defines columns in excel & tabs in word)
  28. $sep = "t"; //tabbed character
  29. //start of printing column names as names of MySQL fields
  30. for ($i = 0; $i < mysql_num_fields($result); $i++) {
  31. echo mysql_field_name($result,$i) . "t";
  32. }
  33. print("n");
  34. //end of printing column names
  35. //start while loop to get data
  36. while($row = mysql_fetch_row($result))
  37. {
  38. $schema_insert = "";
  39. for($j=0; $j<mysql_num_fields($result);$j++)
  40. {
  41. if(!isset($row[$j]))
  42. $schema_insert .= "NULL".$sep;
  43. elseif ($row[$j] != "")
  44. $schema_insert .= "$row[$j]".$sep;
  45. else
  46. $schema_insert .= "NULL".$sep;
  47. }
  48. $schema_insert = str_replace($sep."$", "", $schema_insert);
  49. $schema_insert = preg_replace("/rn|nr|n|r/", " ", $schema_insert);
  50. $schema_insert .= "t";
  51. print(trim($schema_insert));
  52. print "n";
  53. }
  54. ?>
Add Comment
Please, Sign In to add comment