|
|
|
การแสดงเอกสาร pdf โดยการดึงจากฐานข้อมูล ช่วยหน่อยครับ พอดีผมต้องการให้มีการแสดงข้อมูลของตาราง register ด้วยครับ |
|
|
|
|
|
|
|
รบกวนพี่ๆ ช่วยหน่อยน่ะครับ พอดีผมต้องการให้มีการแสดงข้อมูลของตาราง register ด้วยครับ แต่ไม่รู้จะเขียนยังไงครับ ตอนนี้สามารถแสดงของตาราง booking ได้อย่างเดียวครับ
Code (PHP)
<?php
require('../../../FPDF/ThaiPDF.class.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;
}
//Simple table
function BasicTable($header,$data)
{
//Header
$w=array(15,20,25,30,35,25,25);
//Header
$this->Cell(0,5,"TEXT TEXT TEXT TEXT TEXT",0,1);
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(15,6,$eachResult["id_booking"],1,0,'C');
$this->Cell(20,6,$eachResult["id_user"],1,0,'C');
$this->Cell(20,6,$eachResult["id_tour"],1,0,'C');
$this->Cell(25,6,$eachResult["number"],1,0,'C');
$this->Cell(30,6,$eachResult["price_discount"],1,0,'C');
$this->Cell(35,6,$eachResult["date_booking"],1,0,'C');
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(15,20,25,30,35,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(15,6,$eachResult["id_booking"],1,0,'C');
$this->Cell(20,6,$eachResult["id_user"],1,0,'C');
$this->Cell(20,6,$eachResult["id_tour"],1,0,'C');
$this->Cell(25,6,$eachResult["number"],1,0,'C');
$this->Cell(30,6,$eachResult["price_discount"],1,0,'C');
$this->Cell(35,6,$eachResult["date_booking"],1,0,'C');
$this->Ln();
}
//Closure line
$this->Cell(array_sum($w),0,'','T');
}
//Colored table
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(15,20,25,30,35,25,25);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',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->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('รหัสการจอง','รหัสผ้ใช้งาน', 'รหัสทัว', 'ชื่อ','จำนวน','ราคา','วันที่จอง');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","5035512105") or die("Error Connect to Database");
$objDB = mysql_select_db("webapplication");
mysql_query("SET NAMES 'tis620'");// set อักขระให้เป็น Utf8 เพิ่มตรงนี้เลยครับ รับรองได้ชัวครับ
$txtKeyword=$_POST[txtKeyword];
$idtour=$_POST[idtour];
$sql="select * from register where username='$txtKeyword'";
$result1=mysql_query($sql);
$r=mysql_fetch_array($result1);
$id=$r[id];
$username=$r[username];
$lastname=$r[lastname];
$address=$r[address];
$tell=$r[tell];
$resultData1 = array();
for ($i=0;$i<mysql_num_rows($result1);$i++) {
array_push($resultData1,$r);
}
$sql="select * from booking where id_tour='$idtour' and id_user='$id'";
$objQuery = mysql_query($sql);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
$pdf->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
$pdf->AddFont('angsana','I','angsai.php');
$pdf->AddFont('angsana','BI','angsaz.php');
$pdf->SetFont('angsana','',12);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData,$resultData1);
$pdf->Output();
?>
ขอบคุณครับ
Tag : PHP
|
|
|
|
|
|
Date :
2011-12-23 02:02:07 |
By :
ABDulwahed |
View :
886 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|