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 > ในโค้ดการ Export SQL to PDF จะเพิ่มลำดับแถวในคอลั่มอย่างไรครับ



 

ในโค้ดการ Export SQL to PDF จะเพิ่มลำดับแถวในคอลั่มอย่างไรครับ

 



Topic : 096159



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



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




ผมทำตามจากลิงก์นี้ครับ
https://www.thaicreate.com/php/php-pdf-mysql-export-pdf.html
แล้วทีนี้ผมเพิ่มแค่คอลัมน์มา 1 คอลัมน์ แต่ผมจะใส่ลำดับแถว 1 2 3 4 ไปเรื่อยๆ เข้าไปด้วย ต้องทำอย่างไรครับ
จากที่เห็น ผมเพิ่มคอลัมน์ได้ แต่ใส่ลำดับแถวในแต่ละแถวไม่เป็นอ่ะครับ
โค้ดทั้งหมดครับ
Code (PHP)
<?php
$s_id = $_GET['s_id'];
$c_id = $_GET['c_id'];
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(25,30,18,30,30,20,62);
	//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(25,8,$eachResult["number"],1);
		$this->Cell(30,8,$eachResult["std_id"],1);
		$this->Cell(18,8,$eachResult["std_pname"],1);
		$this->Cell(30,8,$eachResult["std_fname"],1);
		$this->Cell(30,8,$eachResult["std_lname"],1);
		$this->Cell(20,8,$eachResult["std_nickname"],1,0,'C');
		$this->Cell(62,8,$eachResult["std_status"],1,0,'C');
		$this->Ln();
	}
}

//Better table
function ImprovedTable($header,$data)
{
	//Column widths
	$w=array(25,18,35,35,20,30);
	//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(25,6,$eachResult["std_id"],1);
		$this->Cell(18,6,$eachResult["std_pname"],1);
		$this->Cell(35,6,$eachResult["std_fname"],1);
		$this->Cell(35,6,$eachResult["std_lname"],1,0,'C');
		$this->Cell(20,6,number_format($eachResult["std_nickname"],2),1,0,'R');
		$this->Cell(30,6,number_format($eachResult["std_mobile"],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(25,18,35,35,20,30);
	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[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,'L',$fill);
		$this->Cell($w[4],6,number_format($row[4]),'LR',0,'C',$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('number','Student ID','Prename','First name','Last name','Nick name','status');
//Data loading

//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","43528071") or die(mysql_error());
$objDB = mysql_select_db("ce");
mysql_query("set NAMES'tis620'"); //
mysql_query("SET character_set_results=tis620"); //
mysql_query("SET character_set_client=tis620"); //
mysql_query("SET character_set_connection=tis620"); //
$strSQL = "SELECT * FROM student WHERE std_id LIKE '$s_id' AND class_id LIKE '%$c_id%' ORDER BY std_id ASC";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);
	array_push($resultData,$result);
}
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวธรรมดา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('browallia','','browa.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา  กำหนด ชื่อ เป็น angsana
$pdf->AddFont('browallia','B','browab.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา  กำหนด ชื่อ เป็น angsana
$pdf->AddFont('browallia','I','browai.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา  กำหนด ชื่อ เป็น angsana
$pdf->AddFont('browallia','BI','browaz.php');
// กำหนดฟอนต์ที่จะใช้  อังสนา ตัวธรรมดา ขนาด 12
$pdf->SetFont('browallia','',16);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('logo.gif',65,8,80);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
$pdf->Output("shotdev/mypdf.pdf","F");
?>




Tag : PHP, MySQL









ประวัติการแก้ไข
2013-06-06 00:31:42
2013-06-06 00:32:28
2013-06-06 00:33:30
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-06-06 00:31:05 By : like-com View : 927 Reply : 3
 

 

No. 1



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



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


โพสต์ดึก คงนอนกันหมดแล้ว
ทำได้แล้วนะครับ ขอบคุณทุกท่านที่กดอ่าน...
Code (PHP)
//Simple table
function BasicTable($header,$data)
{
	//Header
	$w=array(10,25,18,25,25,20,50,18);
	//Header
	for($i=0;$i<count($header);$i++)
		$this->Cell($w[$i],7,$header[$i],1,0,'C');
	$this->Ln();
	$rang = 1;
	//Data
	foreach ($data as $eachResult) 
	{
		$this->Cell(10,8,$rang++,1,0,'C');
		$this->Cell(25,8,$eachResult["std_id"],1);
		$this->Cell(18,8,$eachResult["std_pname"],1);
		$this->Cell(25,8,$eachResult["std_fname"],1);
		$this->Cell(25,8,$eachResult["std_lname"],1);
		$this->Cell(20,8,$eachResult["std_nickname"],1,0,'C');
		$this->Cell(50,8,$eachResult["std_status"],1,0,'C');
		$this->Cell(18,8,$eachResult["note"],1);
		$this->Ln();
	}
}







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-06 03:45:11 By : like-com
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

จัดไปครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-06 06:33:55 By : mr.win
 

 

No. 3



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



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


ขอบคุณมากค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-09 16:58:48 By : phattharachanon
 

   

ค้นหาข้อมูล


   
 

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