Create database latihan;
Setelah itu buat table , copykan syntax berikut
use latihan;
CREATE TABLE `latihan`.`siswa` (
`nis` VARCHAR( 10 ) NOT NULL ,
`nama` VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( `nis` )
) ENGINE = MYISAM ;
lalu isi table nya
INSERT INTO `latihan`.`siswa` (`nis`, `nama`) VALUES ('123', 'Deden'), ('456', 'Deydra');
beres dengan database , kita pindah ke coding phpnya , bagi agan yang belum ada librariesnya download aja dulu di
http://www.4shared.com/zip/JSjGHEt3/plugin_fpdf.htmlreport.php
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
mysql_connect('localhost','root','');
mysql_select_db('latihan');
$pdf->SetFont('Arial','B',20);
$pdf->Cell(30,10,'NIS',1,'L',0);
$pdf->Cell(90,10,'Nama',1,'C',1);
$sql = "select * from siswa";
$query= mysql_query($sql);
while($array=mysql_fetch_array($query)) {
$pdf->Ln();
$pdf->Cell(30,10,$array[0],1,'L',0);
$pdf->Cell(90,10,$array[1],1,'C',1);
}
$pdf->Output('report.pdf','D');
?>
No comments:
Post a Comment