|
|
|
เรียกใช้ คำสั่ง SQL 2 ใน Tableเดียวกัน เพื่อหาค่า Sum ในการexport PDF |
|
|
|
|
|
|
|
Code (PHP)
<?php
require('fpdf.php');
define('FPDF_FONTPATH','font/');
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;
}
function Header()
{
//$this->Image('thaicreate-logo.jpg',87,0,40);
$this->AddFont('angsa','','angsa.php');
$this->SetFont('angsa','',11);
$this->Cell(0,0,iconv( 'UTF-8','TIS-620','หน้าที่ '.$this->PageNo()),0,1,"R");
$this->Ln(20);
}
function Footer()
{
$y=date("Y")+543;
$hh=date("h")+11;
$t=date("$hh:i");
$this->AddFont('angsa','','angsa.php');
$this->SetFont('angsa','',10);
$this->SetY(-15);
$this->Cell(0,0,iconv( 'UTF-8','TIS-620','By... ศูนย์ซ่อมตั้งใจกลการ'),0,1,"L");
$this->Cell(0,0,iconv( 'UTF-8','TIS-620','Create date : '.date("d-m-$y $t")),0,1,"R");
}
//Better table
function table1($header,$data)
{
//Column widths
$w=array(10,20,20,30,25,25,40);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8','TIS-620',$header[$i]),1,0,'C');
$this->Ln();
//Data
$rang = 1;
foreach ($data as $eachdata)
{
$this->Cell(10,6,iconv('UTF-8','TIS-620',$rang++),1,0,'C');
$this->Cell(20,6,iconv('UTF-8','TIS-620',$eachdata["rec_id"]),1);
$this->Cell(20,6,iconv('UTF-8','TIS-620',$eachdata["dd"]),1,0,'C');
$this->Cell(30,6,iconv('UTF-8','TIS-620',,$eachdata["mm"]),1);
$this->Cell(25,6,iconv('UTF-8','TIS-620',$eachdata["yy"]),1,0,'C');
$this->Cell(25,6,iconv('UTF-8','TIS-620',$eachdata["count"].' คัน'),1,0,'C');
$this->Cell(40,6,iconv('UTF-8','TIS-620',$eachdata["name"]),1,0,'L');
$this->Ln();
}
}
}//end class
$pdf=new PDF();
//Column titles
$header=array ('ลำดับ','เลขที่บิล','วัน','เดือน','ปี','รถทั้งหมด','รับรถจาก');
//Data loading
//*** Load MySQL Data ***//
$strSQL = SELECT receive_car.rec_id, receive_car.total_car, trade_member.name, store.dd, store.mm, store.yy
FROM (store INNER JOIN receive_car ON store.rec_id = receive_car.rec_id)
INNER JOIN trade_member ON receive_car.trade_id = trade_member.trade_id
WHERE store.dd = '$dd' and store.mm = '$mm' and store.yy = '$yy' and store.error = '1'
GROUP BY receive_car.rec_id
ORDER BY receive_car.rec_id ;
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($x=0;$x<mysql_num_rows($objQuery);$x++)
{
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
//$pdf->SetFont('Arial','',10);
//*** Table 2 ***//
$pdf->AddPage();
$pdf->AddFont('angsa','','angsa.php');
$pdf->SetFont('angsa','',14);
$pdf->Image('logo.png',85,10,33);// โลโก้
$pdf->Ln(25);
$pdf->table1($header,$resultData);
$pdf->Output("MyPDF/report_store_error.pdf","F");
?>
<a href="MyPDF/report_store_error.pdf"><img src="pic/print.png" title="พิมพ์รายงาน" width="60" height="50" border="0" /></a>
คือต้องการเพิ่ม คำสั่ง SQL อีกตัวนึงซึ่งหาค่า sum ของรถ ไปใน table เดียวกัน
ต้องใช้คำสั่งเรียกยังไงบ้างครับ
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2012-07-17 15:02:31
|
|
|
|
|
Date :
2012-07-17 15:01:25 |
By :
nutsza |
View :
1419 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ค่า count มีค่าหรือเปล่าเห็นตอนquery ไม่มีselect ค่า count เลย
$this->Cell(25,6,iconv('UTF-8','TIS-620',$eachdata["count"].' คัน'),1,0,'C');
|
|
|
|
|
Date :
2012-07-17 16:53:29 |
By :
LuckyStar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|