|
|
|
รบกวนสอบถามเรื่อง fpdf น่ะคะ เรื่องเกี่ยวกับ table |
|
|
|
|
|
|
|
เนื่องจาก ตอนนี้ ทำ Fpdf แล้วอยากให้ ตารางมันไม่เพี้ยนอ่ะค่ะ ช่วยดู Code ให้ทีนะคะ
Code (PHP)
<?php
require('fpdf.php');
class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
$this->Image('header.gif',10,1,180);
//Arial bold 15
$this->SetFont('Arial','B',15);
//Line break
$this->Ln(20);
}
//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Logo
$this->Image('footer.gif',15,285,180);
//Arial italic 8
$this->SetFont('Arial','B',8);
//Page number
$this->MultiCell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
//Colored tabl
e
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(20,20,150,20);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'R',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->MultiCell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'C',$fill);
// $this->Cell($w[4],6,number_format($row[4]),'LR',0,'R',$fill);
// $this->Cell($w[5],6,number_format($row[5]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
//Instanciation of inherited class
$pdf=new PDF ( 'P' , 'mm' , array( 209,298 ) );
//Column titles
$header=array('Name Product','Detail Product','Num','Price');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","nakedkung") or die("Error Connect to Database");
$objDB = mysql_select_db("DB_scpe09");
$strSQL = "SELECT * FROM tb_order";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
$pdf->SetRightMargin( 5 );
$pdf->SetLeftMargin( 5 );
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->FancyTable($header,$resultData);
$pdf->Output();
?>
Tag : PHP, HTML/CSS, JavaScript, jQuery
|
ประวัติการแก้ไข 2010-09-25 11:40:03
|
|
|
|
|
Date :
2010-09-25 09:39:18 |
By :
naked13 |
View :
1503 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|