Anda di halaman 1dari 2

<?

php
$host ="localhost";
$user="root";
$password="";
$database="web2al";
mysql_connect($host,$user,$password) or die("Koneksi server gagal");
mysql_select_db($database);
//Queri untuk Menampilkan data
$query ="SELECT * FROM tb_20130101";
$db_query = mysql_query($query) or die("Query gagal");
//Variabel untuk iterasi
$i = 0;
//Mengambil nilai dari query database
while($data=mysql_fetch_row($db_query))
{
$cell[$i][0] = $data[0];
$cell[$i][1] = $data[1];
$cell[$i][2] = $data[2];
$cell[$i][3] = $data[3];
$i++;
}
require('fpdf/fpdf.php');
class PDF extends FPDF
{
//Fungsi Untuk Membuat Header
function Header()
{
//Pilih font Arial bold 15
$this->SetFont('Arial','B',15);
//Geser ke kanan
$this->Cell(80);
//Judul dalam bingkai
$this->Cell(30,10,'Title',1,0,'C');
//Ganti baris
$this->Ln(1);
}
//Fungsi Untuk Membuat Footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Halaman ke : '.$this->PageNo(),0,0,'C');
}
}
$pdf = new PDF('P','cm','A4');
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("Arial","B",12);
$pdf->Cell(19,1,'Laporan TB Akademik','LRTB',0,'C');
$pdf->Ln();
$pdf->Cell(1,1,'No','LRTB',0,'C');
$pdf->Cell(6,1,'NPM Mahasiswa','LRTB',0,'C');
$pdf->Cell(6,1,'Nama Mahasiswa','LRTB',0,'C');
$pdf->Cell(6,1,'Kode Post','LRTB',0,'C');
$pdf->Ln();

$pdf->SetFont('Times','',10);
for($j=0;$j<$i;$j++)
{
//menampilkan data dari hasil query database
$pdf->Cell(1,1,$j+1,'LBTR',0,'C');
$pdf->Cell(6,1,$cell[$j][0],'LBTR',0,'C');
$pdf->Cell(6,1,$cell[$j][1],'LBTR',0,'C');
$pdf->Cell(6,1,$cell[$j][2],'LBTR',0,'C');
$pdf->Ln();
}
//menampilkan output berupa halaman PDF
$pdf->Output();
?>

Anda mungkin juga menyukai