Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //koneksi ke database
- $link=mysqli_connect("localhost","root","qwerty");
- mysqli_select_db($link,"u377281409_local");
- //mengambil data dari tabel
- $sql=mysqli_query($link,"SELECT * FROM tbl_konsumen ORDER BY user_id");
- $data = array();
- while ($row = mysqli_fetch_assoc($sql)) {
- array_push($data, $row);
- }
- //mengisi judul dan header tabel
- $judul = "DATA KONSUMEN";
- $header = array(
- array("label"=>"ID", "length"=>17, "align"=>"L"),
- array("label"=>"Nama Depan", "length"=>25, "align"=>"L"),
- array("label"=>"Nama Belakang", "length"=>28, "align"=>"L"),
- array("label"=>"Email", "length"=>40, "align"=>"L"),
- array("label"=>"No HP", "length"=>24, "align"=>"L"),
- array("label"=>"Obat yg Dibeli","length"=>25, "align"=>"L"),
- array("label"=>"Jumlah", "length"=>14, "align"=>"L"),
- array("label"=>"Total", "length"=>20, "align"=>"L"),
- );
- //memanggil fpdf
- require_once ("fpdf/fpdf.php");
- $pdf = new FPDF();
- $pdf->AddPage();
- //tampilan Judul Laporan
- $pdf->SetFont('Arial','B','16'); //Font Arial, Tebal/Bold, ukuran font 16
- $pdf->Cell(0,20, $judul, '0', 1, 'C');
- //Header Table
- $pdf->SetFont('Arial','','10');
- $pdf->SetFillColor(42,114,186); //warna dalam kolom header
- $pdf->SetTextColor(255); //warna tulisan putih
- $pdf->SetDrawColor(0,0,0); //warna border
- foreach ($header as $kolom) {
- $pdf->Cell($kolom['length'], 5, $kolom['label'], 5, '0', $kolom['align'], true);
- }
- $pdf->Ln();
- //menampilkan data table
- $pdf->SetFillColor(223,235,248); //warna dalam kolom data
- $pdf->SetTextColor(0); //warna tulisan hitam
- $pdf->SetFont('');
- $fill=false;
- foreach ($data as $baris) {
- $i = 0;
- foreach ($baris as $cell) {
- $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
- $i++;
- }
- $fill = !$fill;
- $pdf->Ln();
- }
- //output file pdf
- ob_end_clean();
- $pdf->Output();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement