<?php
include "koneksi.php";
require('../fpdf19/fpdf.php');

$pdf = new FPDF('L','mm','A4');
$pdf->SetMargins(5,10,5);
$pdf->AddPage();

$pdf->SetFont('Arial','B',12);
$pdf->Cell(0,10,'DATA GURU DAN TENAGA KEPENDIDIKAN',0,1,'C');

$pdf->SetFont('Arial','B',7);

// Header Tabel
$pdf->Cell(8,7,'No',1,0,'C');
$pdf->Cell(28,7,'NUPTK',1,0,'C');
$pdf->Cell(28,7,'Nama',1,0,'C');
$pdf->Cell(12,7,'JK',1,0,'C');
$pdf->Cell(20,7,'Tmp Lahir',1,0,'C');
$pdf->Cell(20,7,'Tgl Lahir',1,0,'C');
$pdf->Cell(15,7,'Status',1,0,'C');
$pdf->Cell(28,7,'Alamat',1,0,'C');
$pdf->Cell(20,7,'Kelurahan',1,0,'C');
$pdf->Cell(20,7,'Kecamatan',1,0,'C');
$pdf->Cell(20,7,'Kab/Kota',1,0,'C');
$pdf->Cell(20,7,'Provinsi',1,0,'C');
$pdf->Cell(15,7,'Kode Pos',1,0,'C');
$pdf->Cell(22,7,'No HP',1,0,'C');
$pdf->Cell(20,7,'Tgl Masuk',1,1,'C');

$query = mysqli_query($link,"SELECT * FROM tb_latihan2");

$no = 1;
$pdf->SetFont('Arial','',6);

while($dt = mysqli_fetch_assoc($query))
{
    // Ambil NUPTK walaupun nama field berbeda
    $nuptk = '';

    if(isset($dt['NUPTK']))
        $nuptk = $dt['NUPTK'];
    elseif(isset($dt['nuptk']))
        $nuptk = $dt['nuptk'];

    $pdf->Cell(8,7,$no++,1,0,'C');
    $pdf->Cell(28,7,$nuptk,1,0,'C');
    $pdf->Cell(28,7,$dt['nama'],1,0,'L');
    $pdf->Cell(12,7,$dt['jns_kelamin'],1,0,'C');
    $pdf->Cell(20,7,$dt['tmp_lahir'],1,0,'C');
    $pdf->Cell(20,7,$dt['tgl_lahir'],1,0,'C');
    $pdf->Cell(15,7,$dt['status'],1,0,'C');
    $pdf->Cell(28,7,$dt['alamat'],1,0,'L');
    $pdf->Cell(20,7,$dt['kelurahan'],1,0,'C');
    $pdf->Cell(20,7,$dt['kecamatan'],1,0,'C');
    $pdf->Cell(20,7,$dt['kab_kota'],1,0,'C');
    $pdf->Cell(20,7,$dt['provinsi'],1,0,'C');
    $pdf->Cell(15,7,$dt['kode_pos'],1,0,'C');
    $pdf->Cell(22,7,$dt['no_hp'],1,0,'C');
    $pdf->Cell(20,7,$dt['tgl_masuk'],1,1,'C');
}

$pdf->Output();
?>