|
|
|
สอบถามเรื่องการสร้าง report ด้วย pdf php โดยดึงข้อมูลจาก database ด้วยค่ะ |
|
|
|
|
|
|
|
ดู Query หน่อยครับ
|
|
|
|
|
Date :
2015-01-23 14:40:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
include ('db_connect.php');
$sql = "SELECT pertype,fname,lname,gender,idcrd FROM hrper";
$result = mysql_query($sql);
$nums = mysql_num_rows($result);
require('fpdf.php');
class PDF extends FPDF {
function SetThaiFont() {
$this->AddFont('AngsanaNew','','angsa.php');
$this->AddFont('AngsanaNew','B','angsab.php');
$this->AddFont('AngsanaNew','I','angsai.php');
$this->AddFont('AngsanaNew','IB','angsaz.php');
$this->AddFont('CordiaNew','','cordia.php');
$this->AddFont('CordiaNew','B','cordiab.php');
$this->AddFont('CordiaNew','I','cordiai.php');
$this->AddFont('CordiaNew','IB','cordiaz.php');
$this->AddFont('Tahoma','','tahoma.php');
$this->AddFont('Tahoma','B','tahomab.php');
$this->AddFont('BrowalliaNew','','browa.php');
$this->AddFont('BrowalliaNew','B','browab.php');
$this->AddFont('BrowalliaNew','I','browai.php');
$this->AddFont('BrowalliaNew','IB','browaz.php');
$this->AddFont('KoHmu','','kohmu.php');
$this->AddFont('KoHmu2','','kohmu2.php');
$this->AddFont('KoHmu3','','kohmu3.php');
$this->AddFont('MicrosoftSansSerif','','micross.php');
$this->AddFont('PLE_Cara','','plecara.php');
$this->AddFont('PLE_Care','','plecare.php');
$this->AddFont('PLE_Care','B','plecareb.php');
$this->AddFont('PLE_Joy','','plejoy.php');
$this->AddFont('PLE_Tom','','pletom.php');
$this->AddFont('PLE_Tom','B','pletomb.php');
$this->AddFont('PLE_TomOutline','','pletomo.php');
$this->AddFont('PLE_TomWide','','pletomw.php');
$this->AddFont('DilleniaUPC','','dill.php');
$this->AddFont('DilleniaUPC','B','dillb.php');
$this->AddFont('DilleniaUPC','I','dilli.php');
$this->AddFont('DilleniaUPC','IB','dillz.php');
$this->AddFont('EucrosiaUPC','','eucro.php');
$this->AddFont('EucrosiaUPC','B','eucrob.php');
$this->AddFont('EucrosiaUPC','I','eucroi.php');
$this->AddFont('EucrosiaUPC','IB','eucroz.php');
$this->AddFont('FreesiaUPC','','free.php');
$this->AddFont('FreesiaUPC','B','freeb.php');
$this->AddFont('FreesiaUPC','I','freei.php');
$this->AddFont('FreesiaUPC','IB','freez.php');
$this->AddFont('IrisUPC','','iris.php');
$this->AddFont('IrisUPC','B','irisb.php');
$this->AddFont('IrisUPC','I','irisi.php');
$this->AddFont('IrisUPC','IB','irisz.php');
$this->AddFont('JasmineUPC','','jasm.php');
$this->AddFont('JasmineUPC','B','jasmb.php');
$this->AddFont('JasmineUPC','I','jasmi.php');
$this->AddFont('JasmineUPC','IB','jasmz.php');
$this->AddFont('KodchiangUPC','','kodc.php');
$this->AddFont('KodchiangUPC','B','kodc.php');
$this->AddFont('KodchiangUPC','I','kodci.php');
$this->AddFont('KodchiangUPC','IB','kodcz.php');
$this->AddFont('LilyUPC','','lily.php');
$this->AddFont('LilyUPC','B','lilyb.php');
$this->AddFont('LilyUPC','I','lilyi.php');
$this->AddFont('LilyUPC','IB','lilyz.php');
}
function conv($string) {
return iconv('UTF-8', 'TIS-620', $string);
}
}
$pdf = new PDF();
$pdf->SetThaiFont();
$pdf->SetMargins(20, 20);
$pdf->AddPage();
$pdf->SetFont('AngsanaNew', 'B', 16);
$txt = $pdf->conv(":: ข้อมูลบุคลากร ::");
$pdf->Cell(0, 0, $txt, 0, 1, 'C');
$pdf->Ln(10);
$pdf->SetFont('AngsanaNew', '', 13);
$txt = $pdf->Cell(40,10,iconv( 'UTF-8','TIS-620','ประเภทพนักงาน'),10,40,"");;
$txt = $pdf->Cell(30,10,iconv( 'UTF-8','TIS-620','ชื่อ'),10,30,"");
$txt = $pdf->Cell(30,10,iconv( 'UTF-8','TIS-620','นามสกุล'),10,30,"");
$txt = $pdf->Cell(20,10,iconv( 'UTF-8','TIS-620','เพศ'),10,30,"");
$txt = $pdf->Cell(30,10,iconv( 'UTF-8','TIS-620','เลขที่บัตรประชาชน'),10,30,"");
$w=array(40,30,30,20,30);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8','TIS-620',$header[$i]),1,0,'c');
while($data=mysql_fetch_array($result)) {
$pertype = $data[0];
$fname = $data[1];
$lname = $data[2];
$gender = $data[3];
$idcrd = $data[4];
$pdf->Ln();
$pdf->Cell(60,10,iconv('','',"{$pertype}"),1,'');
$pdf->Cell(30,10,iconv('','',"{$fname}"),1,'');
$pdf->Cell(30,10,iconv('','',"{$lname}"),1,'');
$pdf->Cell(20,10,iconv('','',"{$gender}"),1,'');
$pdf->Cell(30,10,iconv('','',"{$idcrd}"),1,'');
}
$pdf->Output();
?>
|
|
|
|
|
Date :
2015-01-23 16:08:03 |
By :
khuntong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำแบบปกติฟรีวิวหน้าเว็บให้มันถูกต้องก่อน.. ค่อยใส่ตัว FPDF เข้ามาทีหลังครับ
|
|
|
|
|
Date :
2015-01-23 16:58:08 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ค่ะ ขอบคุณจะลองแก้ไขดูนะค่ะ
|
|
|
|
|
Date :
2015-01-24 11:58:07 |
By :
khuntong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2015-01-24 12:08:43 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|