Advertisement
GWibisono

apa mata anda enak liat beginian?

Jun 2nd, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2. session_start();
  3. define('INC', 1);
  4. include "config.php";
  5. error_reporting(1);
  6. $select = "select * from staff_on_call ";
  7. $export = $db->query($select);
  8. /*
  9. mana error controllernya dimana akan dikasi tau kl export gagal ato tidak??
  10. */
  11. if($export === false){ die('error'); }
  12. $fields = $export->columnCount();
  13. $header=$data='';
  14. for ($i = 0; $i < $fields; $i++) {
  15.     $header .=$export->getColumnMeta($i) . "\t";
  16. }
  17.  
  18. while($export->rowCount()) {
  19. $line = ''; foreach($row as $value) {
  20. if ((!isset($value)) OR ($value == "")) {
  21. $value = "\t";
  22. } else {
  23. $value = str_replace('"', '""', $value);
  24. $value = '"' . $value . '"' . "\t";
  25. }
  26.  
  27. $line .= $value;
  28. } // while
  29. $data .= trim($line)."\n";
  30. }
  31.  
  32. $data = str_replace("\r"," ",$data);
  33. if ($data == "") {
  34.     $data = "n(0) record found!\n";
  35. }else{ }
  36.  
  37. $tanggal=date("Ymd");
  38. header("Content-type: application/x-msdownload");
  39. header("Content-Disposition: attachment; filename=pendaftar_".$tanggal.".csv");
  40. header("Pragma: no-cache");
  41. header("Expires: 0");
  42. print "$header\n$data";
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement