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 > รบกวนพี่ๆหรือท่านอาจารย์ช่วยชี้แนะโค้ด FPDF ให้ผมหน่อยครับ มีปัญหาเรื่องโค้ดภาษาไทยครับ ผมลองพยายามแก้แล้วแต่ยังผิดรบกวนช่วยดูด้วยครับ



 

รบกวนพี่ๆหรือท่านอาจารย์ช่วยชี้แนะโค้ด FPDF ให้ผมหน่อยครับ มีปัญหาเรื่องโค้ดภาษาไทยครับ ผมลองพยายามแก้แล้วแต่ยังผิดรบกวนช่วยดูด้วยครับ

 



Topic : 116164



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



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



รบกวนพี่ๆหรือท่านอาจารย์ช่วยชี้แนะโค้ด FPDF ให้ผมหน่อยครับ มีปัญหาเรื่องโค้ดภาษาไทยครับ ผมลองพยายามแก้แล้วแต่ยังผิดรบกวนช่วยดูด้วยครับ

ภาษาต่างดาวครับ

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<?php
require('fpdf.php');
define('FODF_FONTPATH','font/'); //หาไฟล์ใน folder 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;
}

//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->Cell($w[$i],7,iconv('UTF-8', 'cp874', $header[$i]),1,0,'C');
	$this->Ln();
	//Color and font restoration
	$this->SetFillColor(224,235,255);
	$this->SetTextColor(0);
	$this->SetFont('angsa','',16); //set size
	//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('รหัส','Name','Email','Country Code','Budget','Used');
//Data loading

//*** Load MySQL Data ***//
include"../config.inc.php";
$con = mysql_connect($host,$username,$password);
if (!$con)
  {     die('Could not connect: ' . mysql_error());    }
  mysql_select_db($database, $con);
  mysql_query("SET NAMES UTF8");
 $date_sub=$_REQUEST['date_sub'];
$num=0;
if($date_sub==""){
	$msg="รายงานสินค้าทั้งหมด";
$strSQL="SELECT 
     pd.name_pro as name,
     pd.id_pro as id_pro1,
	 spd.date_sub,
     sum( coalesce( spd.sub_out, 0) ) as quan 
FROM products pd 
LEFT JOIN sub_products spd 
ON pd.id_pro=spd.id_pro
WHERE  spd.sub_out!='0'
GROUP BY  pd.id_pro 
ORDER BY sum( spd.sub_out) DESC LIMIT 3";
}elseif($date_sub!=""){
	$msg="รายงานสินค้าประจำวัน";
	$day_start=$date_sub;
$strSQL="SELECT 
     pd.name_pro as name,
     pd.id_pro as id_pro1,
	 spd.date_sub,
     sum( coalesce( spd.sub_out, 0) ) as quan 
FROM products pd 
LEFT JOIN sub_products spd 
ON pd.id_pro=spd.id_pro
WHERE spd.date_sub='$day_start' and spd.sub_out!='0'
GROUP BY  pd.id_pro 
ORDER BY sum( spd.sub_out) DESC";

}
$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('angsa','','angsa.php');//set font
$pdf->AddFont('angsa','B','angsa.php');
$pdf->AddFont('angsa','I','angsa.php');
$pdf->AddFont('angsa','BI','angsa.php');
$pdf->SetFont('angsa','',12);




//*** 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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-05-01 01:40:26 By : hoyahoya View : 890 Reply : 6
 

 

No. 1



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



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


Code (PHP)
	foreach($data as $row)
	{
		$this->Cell($w[0],6,iconv('UTF-8', 'cp874', $row[0]),'LR',0,'L',$fill);
		$this->Cell($w[1],6,iconv('UTF-8', 'cp874', $row[1]),'LR',0,'L',$fill);
		$this->Cell($w[2],6,iconv('UTF-8', 'cp874', $row[2]),'LR',0,'L',$fill);
		$this->Cell($w[3],6,iconv('UTF-8', 'cp874', $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;
	}


ใช้ iconv แบบนี้ลองแล้วหรือยัง








ประวัติการแก้ไข
2015-05-01 07:57:07
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 07:56:27 By : ipstarone
 


 

No. 2



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



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


ลองดูหัว html กำหนด doctype ถูกหรือเปล่าครับ

html เก่า
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>ThaiCreate.Com PHP PDF</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



้html5
<!doctype html> <html> <head> <meta charset="utf-8">



ประวัติการแก้ไข
2015-05-01 08:02:01
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 08:00:02 By : Chaidhanan
 

 

No. 3



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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


กำหนดหัวต่างๆแล้ว ตัวไฟล์ก็ต้อง Save เป็น utf-8 ด้วยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 08:32:50 By : apisitp
 


 

No. 4



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



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

ตอนนี้ออกแล้วครับแต่ติดปัญหาอยู่ตัวเดียวคือส่วนหัวยังเป็นภาษาต่างดาวอยู่ครับ ผมได้ทำตามที่ พี่ๆแนะนำแล้วครับแต่เหลือจุดเดียวจริงๆครับ

เหลือส่วนหัวครับ

Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
require('fpdf.php');
define('FODF_FONTPATH','font/'); //หาไฟล์ใน folder 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;
}

//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('angsa','',16);
		
	//Header
	$w=array(40,50,45,25,25);/// ปรับความกว้างตาราาง
	for($i=0;$i<count($header);$i++)
		$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
			//$this->Cell($w[$i],7,iconv('UTF-8', 'cp874', $header[$i]),1,0,'C');
	$this->Ln();
	//Color and font restoration
	$this->SetFillColor(224,235,255);
	$this->SetTextColor(0);
	$this->SetFont('angsa','',16); //set size
	//Data
	$fill=false;
	foreach($data as $row)
	{

	$this->Cell($w[0],6,iconv('UTF-8', 'cp874', $row[0]),'LR',0,'L',$fill);
	$this->Cell($w[1],6,iconv('UTF-8', 'cp874', $row[1]),'LR',0,'L',$fill);
	$this->Cell($w[2],6,iconv('UTF-8', 'cp874', $row[2]),'LR',0,'L',$fill);
	$this->Cell($w[3],6,iconv('UTF-8', 'cp874', $row[3]),'LR',0,'C',$fill);
	$this->Cell($w[4],6,number_format($row[4]),'LR',0,'R',$fill);
	$this->Ln();
	$fill=!$fill;
}
	$this->Cell(array_sum($w),0,'','T');
}
}

$pdf=new PDF();
//Column titles
//$this->Cell($w[0],5,iconv('UTF-8', 'cp874', $row[0]),'LR',0,'L',$fill);
$header=array('รหัส','Name','Email','Country Code','Budget');///////////////////////////////////////////////////ส่วนนี้ครับที่ยังเป็นอยู่//////////////////

//Data loading

//*** Load MySQL Data ***//
include"../config.inc.php";
$con = mysql_connect($host,$username,$password);
if (!$con)
  {     die('Could not connect: ' . mysql_error());    }
  mysql_select_db($database, $con);
  mysql_query("SET NAMES UTF8");
 $date_sub=$_REQUEST['date_sub'];
$num=0;
if($date_sub==""){
	$msg="รายงานสินค้าทั้งหมด";
$strSQL="SELECT 
     
     pd.id_pro as id_pro1,
	 pd.name_pro as name,
	 spd.date_sub,
     sum( coalesce( spd.sub_out, 0) ) as quan 
FROM products pd 
LEFT JOIN sub_products spd 
ON pd.id_pro=spd.id_pro
WHERE  spd.sub_out!='0'
GROUP BY  pd.id_pro 
ORDER BY sum( spd.sub_out) DESC LIMIT 3";
}elseif($date_sub!=""){
	$msg="รายงานสินค้าประจำวัน";
	$day_start=$date_sub;
$strSQL="SELECT 
     
     pd.id_pro as id_pro1,
	 pd.name_pro as name,
	 spd.date_sub,
     sum( coalesce( spd.sub_out, 0) ) as quan 
FROM products pd 
LEFT JOIN sub_products spd 
ON pd.id_pro=spd.id_pro
WHERE spd.date_sub='$day_start' and spd.sub_out!='0'
GROUP BY  pd.id_pro 
ORDER BY sum( spd.sub_out) DESC";

}
$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('angsa','','angsa.php');//set font
$pdf->AddFont('angsa','B','angsa.php');
$pdf->AddFont('angsa','I','angsa.php');
$pdf->AddFont('angsa','BI','angsa.php');
$pdf->SetFont('angsa','',16);




//*** 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>
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 09:13:09 By : hoyahoya
 


 

No. 5



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



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


น่าจะไม่ใช่ utf8 แล้วมั้งครับเนี่่ย

บันทัดข้างล่างแสดงได้ถูกต้อง มันไม่ใช่ utf8 แล้วครับ
$this->Cell($w[0],6,iconv('UTF-8', 'cp874', $row[0]),'LR',0,'L',$fill);

เพราะมันแปลง UTF8 ไปเป็น cp874
แต่ส่วนหัว html เป็น utf8

ตอนนี้ผมงงครับ ว่ามันแสดงออกมาได้อย่างไร
รอดูด้วยคน


ประวัติการแก้ไข
2015-05-01 10:47:36
2015-05-01 10:52:18
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 10:44:26 By : Chaidhanan
 


 

No. 6



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



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

ได้แล้วครับ ใส่ตัวนี้ลงไปครับ ผมมองข้ามไปครับ

Code
$this->Cell($w[$i],7,iconv('UTF-8', 'cp874', $header[$i]),1,0,'C',true);


ขอบคุณ อาจารย์แฮค และพี่ๆคนอื่นๆที่ช่วยชี้แนะนะครับ ขอบพระคุณมากๆครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-01 10:49:39 By : hoyahoya
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนพี่ๆหรือท่านอาจารย์ช่วยชี้แนะโค้ด FPDF ให้ผมหน่อยครับ มีปัญหาเรื่องโค้ดภาษาไทยครับ ผมลองพยายามแก้แล้วแต่ยังผิดรบกวนช่วยดูด้วยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่