Advertisement
emperorzaky

Untitled

Jun 21st, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. //koneksi ke database
  3. $link=mysqli_connect("localhost","root","qwerty");
  4. mysqli_select_db($link,"u377281409_local");
  5.  
  6. //mengambil data dari tabel
  7. $sql=mysqli_query($link,"SELECT * FROM tbl_konsumen ORDER BY user_id");
  8. $data = array();
  9. while ($row = mysqli_fetch_assoc($sql)) {
  10. array_push($data, $row);
  11. }
  12.  
  13. //mengisi judul dan header tabel
  14. $judul = "DATA KONSUMEN";
  15. $header = array(
  16. array("label"=>"ID", "length"=>17, "align"=>"L"),
  17. array("label"=>"Nama Depan", "length"=>25, "align"=>"L"),
  18. array("label"=>"Nama Belakang", "length"=>28, "align"=>"L"),
  19. array("label"=>"Email", "length"=>40, "align"=>"L"),
  20. array("label"=>"No HP", "length"=>24, "align"=>"L"),
  21. array("label"=>"Obat yg Dibeli","length"=>25, "align"=>"L"),
  22. array("label"=>"Jumlah", "length"=>14, "align"=>"L"),
  23. array("label"=>"Total", "length"=>20, "align"=>"L"),
  24. );
  25.  
  26. //memanggil fpdf
  27. require_once ("fpdf/fpdf.php");
  28. $pdf = new FPDF();
  29. $pdf->AddPage();
  30.  
  31. //tampilan Judul Laporan
  32. $pdf->SetFont('Arial','B','16'); //Font Arial, Tebal/Bold, ukuran font 16
  33. $pdf->Cell(0,20, $judul, '0', 1, 'C');
  34.  
  35. //Header Table
  36. $pdf->SetFont('Arial','','10');
  37. $pdf->SetFillColor(42,114,186); //warna dalam kolom header
  38. $pdf->SetTextColor(255); //warna tulisan putih
  39. $pdf->SetDrawColor(0,0,0); //warna border
  40. foreach ($header as $kolom) {
  41. $pdf->Cell($kolom['length'], 5, $kolom['label'], 5, '0', $kolom['align'], true);
  42. }
  43. $pdf->Ln();
  44.  
  45. //menampilkan data table
  46. $pdf->SetFillColor(223,235,248); //warna dalam kolom data
  47. $pdf->SetTextColor(0); //warna tulisan hitam
  48. $pdf->SetFont('');
  49. $fill=false;
  50. foreach ($data as $baris) {
  51. $i = 0;
  52. foreach ($baris as $cell) {
  53. $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
  54. $i++;
  55. }
  56. $fill = !$fill;
  57. $pdf->Ln();
  58. }
  59.  
  60. //output file pdf
  61. ob_end_clean();
  62. $pdf->Output();
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement