|
 |
|
สอบถามเรื่อง fpdf การแสดงข้อมูลจากฐานข้อมูลกำหนดให้แสดงหน้าละ 10 แถวมีหัวตาราง และเมื่อครบ 10 แถว ก็ให้ขึ้นหน้าใหม่และแสดงหน้าต่อไปและมีหัวตาราง |
|
 |
|
|
 |
 |
|
ภาพประกอบนะครับ

นี้เป็น code ที่เขียนนะครับ อยากได้แบบแสดงหน้าต่อไปแล้วมีหัวตารางด้วย มีข้อมูลหน้าละ 10 แถวด้วย
Code (PHP)
<head>
<title>report_pointorder</title>
</head>
<body>
<?php
define('FPDF_FONTPATH','font/');
require('fpdf17/fpdf.php');
class PDF extends FPDF
{
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(128,128,128);
$this->SetTextColor(0);
$this->SetDrawColor(0,0,0);
$this->SetLineWidth(.3);
$this->SetFont('angsana','',16);
//Header
$w=array(40,80,40,40,35,40);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],10,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(255,255,255);
$this->SetTextColor(0);
$this->SetFont('angsana','',16);
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],10,$row[0],'LR',0,'C',$fill);
$this->Cell($w[1],10,$row[1],'LR',0,'C',$fill);
$this->Cell($w[2],10,$row[24],'LR',0,'C',$fill);
$this->Cell($w[3],10,$row[14],'LR',0,'C',$fill);
$this->Cell($w[4],10,$row[25],'LR',0,'C',$fill);
$this->Cell($w[5],10,$row[5],'LR',0,'C',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF( 'L' , 'mm' , array( 297,210 ) );
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวธรรมดา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
//Column titles
$header=array(iconv( 'UTF-8','cp874' , 'รหัสสินค้า' ),iconv( 'UTF-8','cp874' , 'ชื่อสินค้า' ),iconv( 'UTF-8','cp874' , 'จุดสั่งซื้อ' ),iconv( 'UTF-8','cp874' , 'จำนวนที่มี' ),iconv( 'UTF-8','cp874' , 'สั่งซื้อครั้งละ' ),iconv( 'UTF-8','cp874' , 'หน่วย' ));
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","123456") or die("Error Connect to Database");
$objDB = mysql_select_db("pharmacy");
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT * FROM drug INNER JOIN store on drug.Drg_Barcode=store.Drg_Barcode WHERE store.Udrg_Odr >= store.Drg_QttNow ";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
$result["Drg_Id"];
$result["Drg_Name"];
$result["Udrg_Odr"];
$result["Drg_QttNow"];
$result["Udrg_OdrQtt"];
$result["Unt_Name"];
array_push($resultData,$result);
}
//************************//
$pdf->SetFont('angsana','',16);
$pdf->AddPage();
$pdf->SetFont('angsana','B',16);
$pdf->setXY( 20, 20 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'รายงานสินค้าถึงจุดสั่งซื้อสินค้า' ) );
$pdf->SetFont('angsana','',16);
$pdf->setXY( 220, 20 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'เลขที่' ) );
$pdf->setXY( 20, 30 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'ร้านยาวิบุญเภสัช' ) );
$pdf->setXY( 205, 30 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'วันที่ '. date('d').'/'. date('m').'/'.( date('Y')+543 ).'' ) );
$pdf->setXY( 260, 30 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'หน้าที่' ) );
$pdf->setXY( 20, 40 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'เลขประจำตัวผู้เสียภาษีอากร 3920600715449' ) );
$pdf->setXY( 20, 50 );
$pdf->MultiCell( 0 , 0 , iconv( 'UTF-8','cp874' , 'เลขที่ 47/17 หมู่ 3 ต. นาเหรง อ. นบพิตำ จ. นครศรีธรรมราช 80160' ) );
$pdf->Ln(15);
$pdf->FancyTable($header,$resultData);
$pdf->Ln();
$pdf->Ln(15);
$pdf->Output("MyPDF/MyPDF_pointorder.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF_pointorder.pdf">here</a> to Download
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2013-11-20 10:38:59 |
By :
nick15 |
View :
2009 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กระทู้นี้ code ไม่ใส่ tag PHP ไม่ให้ผ่านครับ 
|
 |
 |
 |
 |
Date :
2013-11-20 12:13:44 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|