 |
|
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;
}
//Simple table
function BasicTable($header,$data)
{
//Header
$w=array(15,30,40,50,18,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
foreach ($data as $eachResult)
{
$this->Cell(15,6,$eachResult["mUserName"],1,0,'C');
$this->Cell(30,6,$eachResult["mdName"],1,0,'C');
$this->Cell(40,6 ,$eachResult["mdSurname"],1,0,'C');
$this->Cell(50,6 ,$eachResult[""],1,0,'C');
$this->Cell(18,6 ,$eachResult["mdPhone"],1,0,'C');
$this->Cell(40,6 ,$eachResult["mEmail"],1,0,'C');
$this->Ln();
}
}
}
$pdf=new PDF();
//Column titles
$header=array('UserName','ชื่อ','นามสกุล','ที่อยู่ลูกค้า','เบอร์โทรศัพท์','E-mail');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("dbsujaimohom");
mysql_query("collation_database = utf8_thai_ci");
$strSQL = "select * from tblmemberdetail INNER JOIN tblmembers ON tblmemberdetail.ID=tblmembers.ID ";
$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->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
$pdf->AddFont('angsana','I','angsai.php');
$pdf->AddFont('angsana','B','angsaz.php');
$pdf->SetFont('angsana','',12);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Ln(10);
$pdf->BasicTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
$pdf->SetXY(0,5);
$pdf->SetFont('angsana','B',16);$pdf->Write(10,'sujaimohomphare');
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>

Tag : PHP
|
|
 |
 |
 |
 |
Date :
2011-09-22 21:48:28 |
By :
โบ |
View :
999 |
Reply :
16 |
|
 |
 |
 |
 |
|
|
|
 |