|
|
|
เรียกใช้ คำสั่ง SQL 2 ตัวในการ export PDF รบกวนชี้แนะครับ |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
</head>
<body>
<?php
require('fpdf.php');
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(20,30,55,25,25,25);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(20,6,$eachResult["CustomerID"],1);
$this->Cell(30,6,$eachResult["Name"],1);
$this->Cell(55,6,$eachResult["Email"],1);
$this->Cell(25,6,$eachResult["CountryCode"],1,0,'C');
$this->Cell(25,6,number_format($eachResult["Budget"],2),1,0,'R');
$this->Cell(25,6,number_format($eachResult["Budget"],2),1,0,'R');
$this->Ln();
}
//Closure line
$this->Cell(array_sum($w),0,'','T');
}
//Colored table
function FancyTable($header,$data)
{
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($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');
}
}
$pdf=new PDF();
//Column titles
$header=array('ssss','Name','Email','Country Code','Budget','Used');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$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->SetFont('Arial','',10);
//*** Table 2 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
ดาวโหลด <a href="MyPDF/MyPDF.pdf">here</a>
</body>
</html>
ผมต้องการใส่ ตารางเพิ่ม อีกตารางหนึ่งมา ต้องเพิ่ม SQL ตรงไหนเหรอครับ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-07-16 16:33:55 |
By :
nutsza |
View :
1330 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ เด่วจะลองดู
|
ประวัติการแก้ไข 2012-07-17 08:57:10
|
|
|
|
Date :
2012-07-16 16:55:29 |
By :
nutsza |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$pdf->table3($header,$resultData3);
$strSQL = "select * from sell_ss";
$objQuery = mysql_query($strSQL);
$resultData3 = array();
$result = mysql_fetch_array($objQuery);
array_push($resultData3,$result);
function table3($header,$data)
{
foreach ($data as $eachdata)
{
$this->Cell(10,6,iconv('UTF-8','TIS-620',''),0,0);
$this->Cell(60,6,iconv('UTF-8','TIS-620',''),0);
$this->Cell(20,6,iconv('UTF-8','TIS-620',''),0,0);
$this->Cell(25,6,iconv('UTF-8','TIS-620',''),0,0);
$this->Cell(25,6,iconv('UTF-8','TIS-620','ราคารวม'),0,0,'C');
$this->Cell(23,6,iconv('UTF-8','TIS-620',number_format($eachdata["s_buy"],2)),0,0,'R');
$this->Ln();
}
}
เพิ่มแค่นี้ก็ใช้งานได้แล้วครับ
|
|
|
|
|
Date :
2012-07-17 08:58:12 |
By :
nutsza |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แจ่มครับ
|
|
|
|
|
Date :
2012-07-17 20:56:56 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|