Statistics |
|
Total online: 1 Guests: 1 Users: 0 | |
|
|
| | |
|
Membuat pdf dari database
Script code untuk membuat pdf dengan data dari database, dan library fpdf
//koneksi ke database $host = "localhost"; $user = "root"; $pass = ""; $dbnm = "dbmahasiswa"; if ($conn) { if (!$open) { } } else { } //akhir koneksi #ambil data di tabel dan masukkan ke array $query = "SELECT * FROM mhs ORDER BY nama"; } #setting judul laporan dan header tabel $judul = "LAPORAN DATA MAHASISWA"; array("label"=>"NIM", "length"=>30, "align"=>"L"), array("label"=>"NAMA", "length"=>50, "align"=>"L"), array("label"=>"ALAMAT", "length"=>80, "align"=>"L"), array("label"=>"TGL LAHIR", "length"=>30, "align"=>"L") ); #sertakan library FPDF dan bentuk objek require_once ("fpdf16/fpdf.php"); $pdf = new FPDF(); $pdf->AddPage(); #tampilkan judul laporan $pdf->SetFont('Arial','B','16'); $pdf->Cell(0,20, $judul, '0', 1, 'C'); #buat header tabel $pdf->SetFont('Arial','','10'); $pdf->SetFillColor(255,0,0); $pdf->SetTextColor(255); $pdf->SetDrawColor(128,0,0); foreach ($header as $kolom) { $pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], true); } $pdf->Ln(); #tampilkan data tabelnya $pdf->SetFillColor(224,235,255); $pdf->SetTextColor(0); $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 $pdf->Output(); ?> Enter code here
Source: http://achmatim.net/2009/11/29/step-by-step-php-membuat-laporan-pdf-dengan-fpdf/ |
Category: URL web dan Tutorial | Added by: penta (2011-10-11)
|
Views: 7220
| Tags: PHP, mysql, PDF
| Rating: 0.0/0 |
| |
| | |
|
|