Membuat Laporan bentuk PDF

andi · Sep 24, 2011
bang, saya mau buat laporan bentuk PDF pakai FPDF yang referensinya sya dapat dari Modul Achtim tapi setelah saya coba kok malah error berikut adalah coding yang saya buat dan tampilan errornya:
<html>
<body>
<?php
  //koneksi ke database
    $host = "localhost";
    $user = "root";
    $pass = "";
    $dbnm = "aris_com";
 
    $conn = mysql_connect($host, $user, $pass);
    if ($conn) {
       $open = mysql_select_db($dbnm);
    }else {
        die("Server MySql tidak terhubung karena ".mysql_error());
    }
    //akhir koneksi

	  
	#ambil data di tabel dan masukkan ke array

	  
	#ambil data di tabel dan masukkan ke array

    $query = "Select id_raker, realisasi, id_bulan, id_tahun from isiraker";
    $sql   = mysql_query ($query);
    $data  = array();
    while ($row = mysql_fetch_assoc($sql)) {
        array_push($data, $row);
    }
    #setting judul laporan dan header tabel
    $judul  = "Laporan Data Dokter";
    $header = array(
	          array("label"=>"ID RAKER", "length"=>30, "align"=>"L"),
			  array("label"=>"REALISASI","length"=>25, "align"=>"L"),
			  array("label"=>"ID BULAN", "length"=>50, "align"=>"L"),
			  array("label"=>"ID TAHUN", "length"=>20, "align"=>"L")
			  );
    #sertakan library PDF 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();
}

?>
</body>
</html>

6176749336_492ac58dba_b.jpg

apa yang menyebabkan error ini ya bang?
Silahkan login untuk menjawab!
1
Loading...
Ellyx Christian · Sep 26, 2011 · 1 Suka · 0 Tidak Suka
coba pake ini:
<?php
  //koneksi ke database
    $host = "localhost";
    $user = "root";
    $pass = "";
    $dbnm = "aris_com";
 
    $conn = mysql_connect($host, $user, $pass);
    if ($conn) {
       $open = mysql_select_db($dbnm);
    }else {
        die("Server MySql tidak terhubung karena ".mysql_error());
    }
    //akhir koneksi
 
 
	#ambil data di tabel dan masukkan ke array
 
 
	#ambil data di tabel dan masukkan ke array
 
    $query = "Select id_raker, realisasi, id_bulan, id_tahun from isiraker";
    $sql   = mysql_query ($query);
    $data  = array();
    while ($row = mysql_fetch_assoc($sql)) {
        array_push($data, $row);
    }
    #setting judul laporan dan header tabel
    $judul  = "Laporan Data Dokter";
    $header = array(
	          array("label"=>"ID RAKER", "length"=>30, "align"=>"L"),
			  array("label"=>"REALISASI","length"=>25, "align"=>"L"),
			  array("label"=>"ID BULAN", "length"=>50, "align"=>"L"),
			  array("label"=>"ID TAHUN", "length"=>20, "align"=>"L")
			  );
    #sertakan library PDF 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();
0
Loading...
andi · Sep 26, 2011 · 0 Suka · 0 Tidak Suka
bang, masih ngga bisa (masih error). oiya bang klau ada saya minta contoh laporan berdasarkan tahun (jadi ada pilihan combo box berdasarkan tahun gitu). Terimakasih
0
Loading...
Ellyx Christian · Sep 27, 2011 · 0 Suka · 0 Tidak Suka
errornya seperti apa?
1
Loading...
Ellyx Christian · Sep 27, 2011 · 1 Suka · 0 Tidak Suka
yang jelas, sebelum atau sesudah koding diatas tidak boleh ada output apapun (tidak boleh ada spasi, new line, text, tag html dan sebagainya).
0
Loading...
f3_hanung · Apr 20, 2012 · 0 Suka · 0 Tidak Suka
saya dah coba yang dari mas Ellyx diatas, tp masih error. Pesan errornya seperti ini :
1.Notice: Undefined offset: 2 in C:\xampp\htdocs\latihan\taQ\report\repKrit.php on line 36 (error yang pertama),
2.FPDF error: Some data has already been output, can't send PDF file(error yang kedua).
kira-kira apanya ya mas...?
scriptnya seperti ini mas :
<?php
include('../config.php');
//mengambil data dari database :
$sql = mysql_query("select * from kriteria");
$data = array();
while($row = mysql_fetch_assoc($sql)){
array_push($data,$row);
}
//pengaturan judul laporan dan header table :
$judul = "..:: LAPORAN DATA KRITERIA ::..";
$header = array(array("label"=>"Nama Kriteria","length"=>30,"align"=>"L"),array("label"=>"Keterangan","length"=>30,"align"=>"L"));
//mengambil library fpdf :
require_once("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
//menampilkan judul laporan :
$pdf->SetFont('Arial','B','14');
$pdf->Cell(0,20,$judul,'0',1,'C');
//header table :
$pdf->SetFont('Arial','','14');
$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();
//menampilkan data table :
$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();
}
//keluaran file pdf :
$pdf->Output();
?>
0
Loading...
firman · Feb 9, 2013 · 0 Suka · 0 Tidak Suka
Bang Kalau pesan erornya "Server MySQL tidak terhubung karena php_network_getaddresses: getaddrinfo failed: No such host is known. "kira-kira yang salah apanya?
<?php
	$host = "localhost";
	$user = "root";
	$pass = " ";
	$dbnm = "absensi";
	$conn = mysql_connect('$host, $user');
	if ($conn) {
	 $open = mysql_select_db($dbnm);
	 if (!$open) {
	    die ("Database tidak dapat dibuka karena ".mysql_error());
	    }
	} else {
	    die ("Server MySQL tidak terhubung karena ".mysql_error());
	}

	#ambil data di tabel dan masukkan ke array
	$id = $_GET["id"];
	$nama_bulan = array("01"=>"JANUARI","02"=>"FEBRUARI","03"=>"MARET","04"=>"APRIL","05"=>"MEI","06"=>"JUNI",
			    "07"=>"JULI","08"=>"AGUSTUS","09"=>"SEPTEMBER","10"=>"OKTOBER","11"=>"NOVEMBER",
			    "12"=>"DESEMBER");
  	$bulan = substr($id,5,2);
  	$tahun = substr($id,0,4);
  	$tgl = $tahun."-".$bulan;
	$query = "SELECT * FROM absensi,pegawai WHERE absensi.nip=pegawai.nip and tanggal like '%$id-%' 
		  GROUP BY absensi.nip,date_format(tanggal,'%Y-%m')";
        
	$sql = mysql_query($query) or die("Query Gagal");

	
             
	require('../fpdf16/fpdfabsensibulan.php');
	
	class PDF extends FPDF
	{
	 //Fungsi Untuk Membuat Header
	 function Header()
	 {
	  //Pilih font Arial bold 15
	  $this->SetFont('Arial','B',12);
	  
	  //Geser ke kanan
	  $this->Cell(80);
	  
	  //Judul dalam bingkai
	  $this->Cell(0,0,'Title',0,0,'L');

	//Ganti baris
	$this->Ln(1);
	}
	
	//Fungsi Untuk Membuat Footer
	function Footer()
	{
	//Position at 1.5 cm from bottom
	$this->SetY(-5);
	//Arial italic 8
	$this->SetFont('Arial','',8);
	//Page number
	$this->Cell(10,7,'Head office : UPTD Perpustakaan Daerah Purwakarta',10,10,'L');
	}
	}
	
	$pdf = new PDF('P','cm','A4');
	$pdf->Open();
        
	$pdf->AddPage();
	$pdf->image("../images/Logo Kab.jpg",1,1,2,2.5);
	$pdf->SetFont("Arial","B",12);
	$pdf->Cell(19,0,'                 UPTD Perpustakaan Daerah Purwakarta','',1,'L');
        $pdf->SetFont("Arial","",10);
	$pdf->Cell(19,1,'                     Jl. K.K Singawinata No.10','',1,'L');
        $pdf->SetFont("Arial","B",12);
	$pdf->Cell(19,1,'REKAP ABSENSI PEGAWAI','',10,'C');
	$pdf->SetFont("Times","",9);
	$pdf->Cell(19,0,"BULAN ".$nama_bulan[$bulan].' '.$tahun,'',10,'C');
	
	$pdf->SetFont('Times','',10);
	$pdf->Cell(1,1,'','',0,'C');
	$pdf->Cell(3,1,'','',0,'L');
	$pdf->Cell(15,1,'','',0,'L');
	$pdf->Ln();
	$pdf->SetFont('Times','B',10);
	$pdf->Cell(1,1,"No.",'LBTR',0,'C');
	$pdf->Cell(4,1,"NIP",'LBTR',0,'C');
	$pdf->Cell(8,1,"Nama Pegawai",'LBTR',0,'C');
	$pdf->Cell(1,1,"H",'LBTR',0,'C');
	$pdf->Cell(1,1,"S",'LBTR',0,'C');
	$pdf->Cell(1,1,"I",'LBTR',0,'C');
	$pdf->Cell(1,1,"C",'LBTR',0,'C');
	$pdf->Cell(1,1,"DL",'LBTR',0,'C');
	$pdf->Cell(1,1,"TK",'LBTR',0,'C');
	$pdf->Ln();

	$pdf->SetFont('Times','',10);
	$no=1; 
	while($row = mysql_fetch_array($sql))
  	{
  	$nip = $row["nip"];
	$nama_pegawai = $row["nama"];
  	

   $h = mysql_query("select COUNT(*) as h FROM absensi where kehadiran='H' and nip='$nip' and tanggal
			   like '%$id%'");
         $hadir = mysql_fetch_array($h);
         $totalhadir = $hadir["h"];
         $s = mysql_query("select COUNT(*) as s FROM absensi where kehadiran='S' and nip='$nip' and tanggal
			   like '%$id%'");
         $sakit = mysql_fetch_array($s);
         $totalsakit = $sakit["s"];
         $i = mysql_query("select COUNT(*) as i FROM absensi where kehadiran='I' and nip='$nip' and tanggal
			   like '%$id%'");
         $izin = mysql_fetch_array($i);
         $totalizin = $izin["i"];
         $c = mysql_query("select COUNT(*) as c FROM absensi where kehadiran='C' and nip='$nip' and tanggal
			   like '%$id%'");
         $cuti = mysql_fetch_array($c);
         $totalcuti = $cuti["c"];
         $dl = mysql_query("select COUNT(*) as dl FROM absensi where kehadiran='DL' and nip='$nip' and tanggal
			   like '%$id%'");
         $dinasluar = mysql_fetch_array($dl);
         $totaldinasluar = $dinasluar["dl"];
         $tk = mysql_query("select COUNT(*) as tk FROM absensi where kehadiran='TK' and nip='$nip' and tanggal
			   like '%$id%'");
         $tanpaketerangan = mysql_fetch_array($tk);
         $totaltanpaketerangan = $tanpaketerangan["tk"];

	//menampilkan data dari hasil query database
	$pdf->Cell(1,1,$no.'.','LBTR',0,'C');
	$pdf->Cell(4,1,$nip,'LBTR',0,'C');
	$pdf->Cell(8,1,$nama_pegawai,'LBTR',0,'L');
	$pdf->Cell(1,1,$totalhadir,'LBTR',0,'C');
	$pdf->Cell(1,1,$totalsakit,'LBTR',0,'C');
	$pdf->Cell(1,1,$totalizin,'LBTR',0,'C');
	$pdf->Cell(1,1,$totalcuti,'LBTR',0,'C');
	$pdf->Cell(1,1,$totaldinasluar,'LBTR',0,'C');
	$pdf->Cell(1,1,$totaltanpaketerangan,'LBTR',0,'C');
	$pdf->Ln();
	$no++;
        }
	$pdf->SetFont("Times","",10);
	$pdf->Cell(19,1,'Keterangan :','',0,'L');
	$pdf->Ln();
	$pdf->SetFont("Times","",10);
	$pdf->Cell(19,0,'H = Hadir, S = Sakit, I = Izin, C = Cuti, DL = Dinas Luar, TK = Tanpa Keterangan','',0,'L');
	$pdf->Ln();
	$pdf->SetFont("Times","",10);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,'','',0,'C');
	$pdf->Ln();
        $pdf->SetFont("Times","",10);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,'Mengetahui,','',0,'C');
	$pdf->Ln();
	$pdf->SetFont("Times","",10);
	$pdf->Cell(8,0,'','',0,'C');
	$pdf->Cell(4,0,'','',0,'C');
	$pdf->Cell(7,0,'Kepala Perpustakaan','',0,'C');
	$pdf->Ln();
	$pdf->SetFont("Times","B",9);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,'','',0,'C');
	$pdf->SetFont("Times","B",9);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,'','',0,'C');
	$pdf->Ln();
	$pdf->SetFont("Times","U",10);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,"( Nina Aminah Bajri, SH )",'',0,'C');
	$pdf->Ln();
	$pdf->SetFont("Times","",10);
	$pdf->Cell(8,0,"",'',0,'C');
	$pdf->Cell(4,0,"",'',0,'C');
	$pdf->Cell(7,0,"NIP : 196203161997032001",'',0,'C');
	$pdf->Ln();
        $pdf->SetFont("Times","U",10);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,"",'',0,'C');
	$pdf->Ln();
	$pdf->SetFont("Times","U",10);
	$pdf->Cell(8,1,'','',0,'C');
	$pdf->Cell(4,1,'','',0,'C');
	$pdf->Cell(7,1,"",'',0,'C');
	$pdf->Ln();
	//menampilkan output berupa halaman PDF
	$pdf->Output();
?>
0
Loading...
Ellyx Christian · Feb 11, 2013 · 0 Suka · 0 Tidak Suka
coba ganti localhost dengan 127.0.0.1
0
Loading...
firman · Feb 12, 2013 · 0 Suka · 0 Tidak Suka
localhost udah ditubah tapi Tetep ya bang,,,kira2 kenapa?
0
Loading...
Ellyx Christian · Feb 21, 2013 · 0 Suka · 0 Tidak Suka
kalau pake phpMyAdmin mau jalan ga?
0
Loading...
firman · Feb 21, 2013 · 0 Suka · 0 Tidak Suka
Engga bang,,saya pake xampp 1.7.4.
udah pake segala cara tetep aja.
mohon pencerahannya.