Guest User

Untitled

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