Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > รบกวนสอบถามด้วยครับ ผมดึงข้้อมูลจาก mysql แล้วจะให้ออกเป็น PDF โดยทำตามที่พี่วิน POST เอาไว้ ปรากฏว่าไม่ได้ครับ ไม่รู้ว่าผิดตรงไหน ช่วยด้วยนะครับ



 

รบกวนสอบถามด้วยครับ ผมดึงข้้อมูลจาก mysql แล้วจะให้ออกเป็น PDF โดยทำตามที่พี่วิน POST เอาไว้ ปรากฏว่าไม่ได้ครับ ไม่รู้ว่าผิดตรงไหน ช่วยด้วยนะครับ

 



Topic : 088025



โพสกระทู้ ( 150 )
บทความ ( 0 )



สถานะออฟไลน์




รบกวนสอบถามด้วยครับ ผมดึงข้้อมูลจาก mysql แล้วจะให้ออกเป็น PDF โดยทำตามที่พี่วิน POST เอาไว้ ปรากฏว่าไม่ได้ครับ ไม่รู้ว่าผิดตรงไหน ช่วยด้วยนะครับ

Code (code ครับ)
<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;
}

//Simple table
function BasicTable($header,$data)
{
	//Header
	$w=array(30,30,55,25,20,20);
	//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(30,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(20,6,$eachResult["Budget"],1);
		$this->Cell(20,6,$eachResult["Budget"],1);
		$this->Ln();
	}
}

//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)
{
	//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,30,55,25,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('CustomerID','name','Email','Country Code','Budget','Used');
//Data loading

//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("parttime");
$strSQL = "SELECT * FROM parttime WHERE gender='ชาย'";
$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 3 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);

$pdf->Output("MyPDF/MyPDF.pdf","F");
?>

PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>




Tag : PHP, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-12-14 16:35:48 By : sranuwat View : 862 Reply : 6
 

 

No. 1



โพสกระทู้ ( 150 )
บทความ ( 0 )



สถานะออฟไลน์


ผลที่ได้เป็นแบบนี้ครับ มีแต่หัว

PDF ERROR






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-14 16:40:26 By : sranuwat
 


 

No. 2



โพสกระทู้ ( 25 )
บทความ ( 0 )



สถานะออฟไลน์


ผมเคยลองทำนะครับ เดี๋ยวจะหาที่ผมทำมาให้ดูครับ ดึงได แต่ติดอย่างเดียวที่มันไม่เว้นบรรทัดอัตโนมัตน่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-14 16:53:58 By : creativegu
 

 

No. 3



โพสกระทู้ ( 150 )
บทความ ( 0 )



สถานะออฟไลน์


ได้แล้วครับ แต่ว่าที่หน้าที่ 2 หัวแถวไม่โชว์ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-14 18:31:22 By : sranuwat
 


 

No. 4



โพสกระทู้ ( 150 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่มีหัวคอลัมน์แบบนี้ครับ

ืNO HEADER
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-14 18:33:50 By : sranuwat
 


 

No. 5



โพสกระทู้ ( 25 )
บทความ ( 0 )



สถานะออฟไลน์


นี่ครับโค้ด ผมรู้สึกว่าตอนนั้นผมใช้ตัวฟอร์มที่ 2 น่ัะครับ ยังใงลองเอาไปปรับแก้เอานะครับ

Code (PHP)
<?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(90,90); 
//Header 
for($i=0;$i<count($header);$i++) 
$this->Cell($w[$i],7,$header[$i],1,0,'L'); 
//$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');    
$this->Ln(); 
//Data 
foreach ($data as $eachResult) 
{ 
$this->Cell(90,6,$eachResult["member_id"],1,0); 
$this->Cell(90,6,$eachResult["status"],1,3); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
	{
		$this->Cell(180,6,'Member CV by Sayhires.Com',0,1);
		$this->Cell(180,6,$eachResult[""],0);
		$this->Ln();
	}
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','ชื่อต้น | Title :'),0,0,'L');
$this->Cell(120,6,$eachResult["title_name"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','ชื่อ :'),0,0,'L');
$this->Cell(120,6,$eachResult["name"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','นามสกุล :'),0,0,'L');
$this->Cell(120,6,$eachResult["surname"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','ชื่อ ภาษาอังกฤษ| Name :'),0,0,'L');
$this->Cell(120,6,$eachResult["ename"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','นามสกุล ภาษาอังกฤษ| Surname :'),0,0,'L');
$this->Cell(120,6,$eachResult["esurname"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','เพศ| Sex :'),0,0,'L');
$this->Cell(120,6,$eachResult["sex"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','วัน / เดือน / ปี เกิด| ฺBirth date :'),0,0,'L');
$this->Cell(5,6,$eachResult["date"],0,0,'L'); 
$this->Cell(20,6,$eachResult["month"],0,0,'L'); 
$this->Cell(10,6,$eachResult["year"],0,0,'R'); 
$this->Cell(40,6,iconv( 'UTF-8','TIS-620','อายุ | ฺAge :'),0,0,'R');
$this->Cell(5,6,$eachResult["age"],0,0,'L'); 
$this->Cell(10,6,iconv( 'UTF-8','TIS-620','ปี | ฺYears old '),0,0,'L');
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C'); 
$this->Ln(); 
} 
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','สถานที่เกิด | Birth place:'),0,0,'L');
$this->Cell(120,6,$eachResult["pbirth"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','เชื้อชาติ| Nationality :'),0,0,'L');
$this->Cell(25,6,$eachResult["nation"],0,0,'L'); 
$this->Cell(40,6,iconv( 'UTF-8','TIS-620','ศาสนา | Religion :'),0,0,'R');
$this->Cell(15,6,$eachResult["religion"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
}
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','ส่วนสูง | Height :'),0,0,'L');
$this->Cell(15,6,$eachResult["height"],0,0,'L'); 
$this->Cell(10,6,iconv( 'UTF-8','TIS-620','ซม | cm'),0,0,'L');
$this->Cell(40,6,iconv( 'UTF-8','TIS-620','น้ำหนัก| Weight :'),0,0,'R');
$this->Cell(15,6,$eachResult["weight"],0,0,'L'); 
$this->Cell(10,6,iconv( 'UTF-8','TIS-620','กก | KG'),0,0,'L');

//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
}
{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','หมายเลขบัตรประชาชน | ID no:'),0,0,'L');
$this->Cell(120,6,$eachResult["id_card"],0,3,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
	{
		$this->Cell(180,6,iconv( 'UTF-8','TIS-620','ข้อมูลติดต่อ | Contact detail'),0,0,'L');
		$this->Cell(180,6,$eachResult[""],0,1);
		$this->Ln();
	}
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','ที่อยู่ปัจจุบัน | Address :'),0,0,'L');
$this->Cell(40,6,$eachResult["paddress"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620',''),0,0,'L');
$this->Cell(15,6,$eachResult["amper"],0,0,'L'); 
$this->Cell(15,6,$eachResult["province"],0,0,'L'); 
$this->Cell(15,6,$eachResult["country"],0,0,'L'); 
$this->Cell(15,6,$eachResult["zipcode"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','โทรศัพท์บ้าน | House phone'),0,0,'L');
$this->Cell(15,6,$eachResult["hphone"],0,0,'L'); 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','โทรศัพท์มือถือ| Mobile phone'),0,0,'R');
$this->Cell(15,6,$eachResult["phone"],0,0,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
	{ 
$this->Cell(60,6,iconv( 'UTF-8','TIS-620','อีเมล์ติดต่อ| Email'),0,0,'L');
$this->Cell(120,6,$eachResult["email"],0,3,'L'); 
//$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,3,'C'); 
$this->Ln(); 
} 
 
//Closure line 
$this->Cell(array_sum($w),0,'','T'); 
} 

} 
$pdf=new PDF(); 
//Column titles 
$header=array('Member_id','Status');
//Data loading 
//*** Load MySQL Data ***// 
$objConnect = mysql_connect("localhost","root","xxx") or die("Error Connect to Database");
$objDB = mysql_select_db("DB_name");
//mysql_query("set NAMES'UTF8'");// set ÍÑ¡¢ÃÐãËéà»ç¹ Utf8  à¾ÔèÁµÃ§¹ÕéàŤÃѺ   ÃѺÃͧä´éªÑǤÃѺ 
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT * FROM table WHERE id = '".$_GET["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','BI','angsaz.php'); 
define('FPDF_FONTPATH','font/');
	$pdf->AddFont('angsa','','angsa.php');
$pdf->AddFont('angsa','B','angsab.php'); 
$pdf->AddFont('angsa','I','angsai.php'); 
$pdf->AddFont('angsa','BI','angsaz.php'); 
	$pdf->SetFont('angsa','',16);

//*** Table 2 ***// 
$pdf->AddPage(); 
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35); 
$pdf->ImprovedTable($header,$resultData); 


$pdf->Output("MyPDF/MyPDF.pdf","F"); 
?> 
<CENTER><TD>Report PDF.  <a href="MyPDF/MyPDF.pdf" target='_parent'>Click here</a> to Download </TD></CENTER>
</body> 
</html>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-15 07:11:17 By : creativegu
 


 

No. 6



โพสกระทู้ ( 150 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ คุณ creativegu นะครับ แต่กรณีขึ้นหน้าสองยังไม่ได้เลยคร้บ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-15 10:33:36 By : sranuwat
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนสอบถามด้วยครับ ผมดึงข้้อมูลจาก mysql แล้วจะให้ออกเป็น PDF โดยทำตามที่พี่วิน POST เอาไว้ ปรากฏว่าไม่ได้ครับ ไม่รู้ว่าผิดตรงไหน ช่วยด้วยนะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่