|
|
|
สร้าง pdf แล้ว query ข้อมูล โดยมีแถบหัวตารางทุกครั้ง เมื่อขึ้นหน้าใหม่ |
|
|
|
|
|
|
|
อยากให้หน้า 2 ขึ้นแถบหัวข้อตารางเหมือนหน้า 1 โดยการqueryข้อมูล แล้วกำหนดว่าให้หน้า 1 แสดงแค่ 38 ลำดับ แล้วพอครบก็ให้แสดงหน้าใหม่ พร้อมมีหัวตารางมาด้วย ต้องทำยังไงค่ะ ขอบคุณค่ะ
หน้า1
หน้า2
Code (PHP)
@session_start();
require_once('./config/lang/eng.php');
require_once('./tcpdf.php');
// create new PDF document
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->setViewerPreferences(array('PrintScaling' => 'None'));
$pageDimensions = $pdf->getPageDimensions();
$yOffset = ceil($pdf->GetY());
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_FOOTER);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('thsarabun', '', 14);
$pdf->SetMargins(12, 15, 10, true);
$pdf->AddPage();
require 'databases.php';
require './academicyear.php';
$html = '
<h3 align="center">
แบบรายงานผลการประเมินวิทยานิพนธ์/สารนิพนธ์<br/>
ประจำภาคการศึกษาที่ '.$_POST['term'].'/'.$_POST['year'].'<br/>
</h3>
<table border="1">
<tr>
<td width="25" rowspan="2" align="center" style="font-weight:bold;">ที่</td>
<td width="100" rowspan="2" align="center" style="font-weight:bold;">รหัสประจำตัว</td>
<td width="230" rowspan="2" align="center" style="font-weight:bold;">ชื่อ-สกุล (รหัสวิชาวิทยานิพนธ์)</td>
<td width="60" rowspan="2" align="center" style="font-weight:bold;">สาขาวิชา</td>
<td width="185" colspan="3" align="center" style="font-weight:bold;">หน่วยกิตวิทยานิพนธ์/สารนิพนธ์</td>
<td width="60" colspan="2" align="center" style="font-weight:bold;">หน่วยกิต</td>
</tr>
<tr>
<td width="75" align="center" style="font-weight:bold;">ตามหลักสูตร</td>
<td width="45" align="center" style="font-weight:bold;">สะสม</td>
<td width="65" align="center" style="font-weight:bold;">ลงทะเบียน</td>
<td width="30" align="center" style="font-weight:bold;">IP</td>
<td width="30" align="center" style="font-weight:bold;">U</td>
</tr>';
$db = new databases();
$sql = "SELECT * FROM student LEFT JOIN session ON (student.Std_Session_Code=session.Session_Code) LEFT JOIN major ON (student.Std_Major_Code=major.Major_Code) LEFT JOIN std_type ON (std_type.Std_Type_Code=student.Std_Type_Code) LEFT JOIN estimate ON ((student.Std_Code=estimate.Reg_Std_Code) AND (estimate.Etm_Term=$_POST[term] AND estimate.Etm_Year=$_POST[year])) LEFT JOIN register ON (student.Std_Code=register.Reg_Std_Code) LEFT JOIN register_course ON ((student.Std_Code=register_course.Reg_Std_Code) AND (register_course.Reg_Term=$_POST[term] AND register_course.Reg_Year=$_POST[year]) AND (register_course.Reg_Course_ID='463004' OR register_course.Reg_Course_ID='463005')) LEFT JOIN applicable_course ON (register_course.Reg_Course_ID=applicable_course.Course_ID) WHERE (estimate.Etm_Pfs_Code_Main1='' AND estimate.Etm_Pfs_Code_Main2='') AND (estimate.Etm_Term =$_POST[term] and estimate.Etm_Year =$_POST[year]) ORDER BY session.Session_Name_Eng ASC, estimate.Etm_term ASC, estimate.Etm_Year ASC, student.Std_Code ASC";
$data_estimate = mysql_query($sql);
$rows = mysql_num_rows($data_estimate);
$i=0;
$pass=0;
while($data = mysql_fetch_array($data_estimate)){
$html .= '<tr>
<td width="25" align="center">'. ++$i .'</td>
<td width="100" align="center">'. $data['Std_Code'] .'</td>
<td width="230"> '. $data['Std_Name'] .' ('. $data['Reg_Course_ID'] .')</td>
<td width="60" align="center">'. $data['Session_Name_Eng'] .'</td>
<td width="75" align="center">'. $data['Course_Unit'] .'</td>
<td width="45" align="center">'. $data['Etm_Cumulative_Unit'] .'</td>
<td width="65" align="center">'. $data['Reg_Master_Thesis_Unit'] .'</td>
<td width="30" align="center">'. $data['Etm_IP'] .'</td>';
$reg_unit=$data['Reg_Master_Thesis_Unit'];
$pass_unit=$data['Etm_IP'];
$nopass_unit=$reg_unit-$pass_unit;
$html .= '<td width="30" align="center">'. $nopass_unit .'</td>
</tr>';
if($data['Etm_IP']!=0){
$pass++;
}
}
$nopass = $i-$pass;
$sql_master = "SELECT * FROM professor WHERE Pfs_Type_Code='1'";
$query_master = mysql_query($sql_master);
$data_master = mysql_fetch_array($query_master);
$html .= '</table>
<h4>ทั้งหมด '. $i .' คน : ผ่าน '. $pass .' คน ไม่ผ่าน '. $nopass .' คน<br/></h4>
$pdf->writeHTML($html, true, false, true, false, '');
//$pdf->writeHTML(UTFEncode('HTML'));
$pdf->lastPage();
ob_clean();
$pdf->Output('report.pdf', 'I');
Tag : PHP
|
ประวัติการแก้ไข 2013-05-01 13:19:52 2013-05-01 13:29:10
|
|
|
|
|
Date :
2013-05-01 13:15:05 |
By :
nickiie |
View :
3347 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเข้าไปอดูตัวอย่างบทความการแบ่งหน้าของ PHP และ MySQL จากนั้นค่อย ๆ นำมา Apply กับ Code ครับ
|
|
|
|
|
Date :
2013-05-01 22:07:01 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2013-05-01 22:07:01
รายละเอียดของการตอบ ::
ทำแล้วนะค่ะ แบ่งให้หน้านึงมี37แถวเสร็จ แล้วทีนี้โชว์แค่หน้าเดียว ไม่ขึ้นหน้าใหม่ให้เลยค่ะ รบกวนด้วยนะค่ะ
Code (PHP)
<?php
@session_start();
require_once('./config/lang/eng.php');
require_once('./tcpdf.php');
require 'databases.php';
$db = new databases();
require './academicyear.php';
$aka = $_SESSION['aka'];
$advisor=$_POST['advisor'];
// create new PDF document
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->setViewerPreferences(array('PrintScaling' => 'None'));
$pageDimensions = $pdf->getPageDimensions();
$yOffset = ceil($pdf->GetY());
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
//$pdf->SetMargins(5, 3, 6, false);
//$pdf->SetHeaderMargin('100');
//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_FOOTER);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('thsarabun', '', 14);
$pdf->SetMargins(12, 15, 10, true);
$pdf->AddPage();
//============================================PAGE==============================================
$data_estimate = mysql_query($sql);
$Num_Rows = mysql_num_rows($data_estimate);
$Per_Page = 37; // หน้านึงให้แสดงข้อมูล 5 อัน
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
//============================================END PAGE=================================================
if($advisor!=''){
$sql = "SELECT * FROM student LEFT JOIN session ON (student.Std_Session_Code=session.Session_Code) LEFT JOIN major ON (student.Std_Major_Code=major.Major_Code) LEFT JOIN std_type ON (std_type.Std_Type_Code=student.Std_Type_Code) LEFT JOIN estimate ON ((student.Std_Code=estimate.Reg_Std_Code) AND (estimate.Etm_Term=$_POST[term] AND estimate.Etm_Year=$_POST[year])) LEFT JOIN register ON (student.Std_Code=register.Reg_Std_Code) LEFT JOIN register_course ON ((student.Std_Code=register_course.Reg_Std_Code) AND (register_course.Reg_Term=$_POST[term] AND register_course.Reg_Year=$_POST[year]) AND (register_course.Reg_Course_ID='463004' OR register_course.Reg_Course_ID='463005')) LEFT JOIN applicable_course ON (register_course.Reg_Course_ID=applicable_course.Course_ID) WHERE (estimate.Etm_Pfs_Code_Main1='$advisor' OR estimate.Etm_Pfs_Code_Main2='$advisor') AND (estimate.Etm_Term =$_POST[term] and estimate.Etm_Year =$_POST[year]) ORDER BY session.Session_Name_Eng ASC, estimate.Etm_term ASC, estimate.Etm_Year ASC, student.Std_Code ASC LIMIT $Page_Start , $Per_Page";
}
else if($advisor==''){
$sql = "SELECT * FROM student LEFT JOIN session ON (student.Std_Session_Code=session.Session_Code) LEFT JOIN major ON (student.Std_Major_Code=major.Major_Code) LEFT JOIN std_type ON (std_type.Std_Type_Code=student.Std_Type_Code) LEFT JOIN estimate ON ((student.Std_Code=estimate.Reg_Std_Code) AND (estimate.Etm_Term=$_POST[term] AND estimate.Etm_Year=$_POST[year])) LEFT JOIN register ON (student.Std_Code=register.Reg_Std_Code) LEFT JOIN register_course ON ((student.Std_Code=register_course.Reg_Std_Code) AND (register_course.Reg_Term=$_POST[term] AND register_course.Reg_Year=$_POST[year]) AND (register_course.Reg_Course_ID='463004' OR register_course.Reg_Course_ID='463005')) LEFT JOIN applicable_course ON (register_course.Reg_Course_ID=applicable_course.Course_ID) WHERE (estimate.Etm_Pfs_Code_Main1='$advisor' AND estimate.Etm_Pfs_Code_Main2='$advisor') AND (estimate.Etm_Term =$_POST[term] and estimate.Etm_Year =$_POST[year]) ORDER BY session.Session_Name_Eng ASC, estimate.Etm_term ASC, estimate.Etm_Year ASC, student.Std_Code ASC LIMIT $Page_Start , $Per_Page";
}
$data_estimate = mysql_query($sql);
$html = '
<h3 align="center">
แบบรายงานผลการประเมินวิทยานิพนธ์/สารนิพนธ์<br/>
ประจำภาคการศึกษาที่ '.$_POST['term'].'/'.$_POST['year'].'<br/>
</h3>
<table border="1">
<tr>
<td width="25" rowspan="2" align="center" style="font-weight:bold;">ที่</td>
<td width="100" rowspan="2" align="center" style="font-weight:bold;">รหัสประจำตัว</td>
<td width="230" rowspan="2" align="center" style="font-weight:bold;">ชื่อ-สกุล (รหัสวิชาวิทยานิพนธ์)</td>
<td width="60" rowspan="2" align="center" style="font-weight:bold;">สาขาวิชา</td>
<td width="185" colspan="3" align="center" style="font-weight:bold;">หน่วยกิตวิทยานิพนธ์/สารนิพนธ์</td>
<td width="60" colspan="2" align="center" style="font-weight:bold;">หน่วยกิต</td>
</tr>
<tr>
<td width="75" align="center" style="font-weight:bold;">ตามหลักสูตร</td>
<td width="45" align="center" style="font-weight:bold;">สะสม</td>
<td width="65" align="center" style="font-weight:bold;">ลงทะเบียน</td>
<td width="30" align="center" style="font-weight:bold;">IP</td>
<td width="30" align="center" style="font-weight:bold;">U</td>
</tr>';
$i = $Page_Start+1;
$pass=0;
while($data = mysql_fetch_array($data_estimate)){
$html .= '<tr>
<td width="25" align="center">'. $i .'</td>
<td width="100" align="center">'. $data['Std_Code'] .'</td>
<td width="230"> '. $data['Std_Name'] .' ('. $data['Reg_Course_ID'] .')</td>
<td width="60" align="center">'. $data['Session_Name_Eng'] .'</td>
<td width="75" align="center">'. $data['Course_Unit'] .'</td>
<td width="45" align="center">'. $data['Etm_Cumulative_Unit'] .'</td>
<td width="65" align="center">'. $data['Reg_Master_Thesis_Unit'] .'</td>
<td width="30" align="center">'. $data['Etm_IP'] .'</td>';
$reg_unit=$data['Reg_Master_Thesis_Unit'];
$pass_unit=$data['Etm_IP'];
$nopass_unit=$reg_unit-$pass_unit;
$html .= '<td width="30" align="center">'. $nopass_unit .'</td>
</tr>';
if($data['Etm_IP']!=0){
$pass++;
}
$i++;
}
$pdf->writeHTML($html, true, false, true, false, '');
//$pdf->writeHTML(UTFEncode('HTML'));
$pdf->lastPage();
ob_clean();
$pdf->Output('report.pdf', 'I');
|
|
|
|
|
Date :
2013-05-02 10:37:30 |
By :
nickiie |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
class PDF extends FPDF{
//Page header
function Header()
{
$this->Text(18,12,iconv("UTF-8","TIS-620","แบบรายงานผล"),1,0);
}
|
ประวัติการแก้ไข 2013-05-02 10:58:30
|
|
|
|
Date :
2013-05-02 10:57:50 |
By :
nattkhanesha |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|