จะเลือกข้อมูลให้แสดงรายงาน ชื่อนักศึกษาแต่ละสาขา เป็น pdf โดยใช้ listbox 3 ชั้นอย่างไรครับ
จากฐานข้อมูลประมาณนี้ครับ
ต้องทำ list box 3 ชั้น โดยเลือก ชั้นปี คณะ สาขา แล้วรายงานเป็น PDF อะครับ
ดู code แล้วไม่ค่อยเข้าใจเลย มืดมนไปหมดแล้วครับ
ทำได้แค่ฟอร์ม แค่นี้อะครับ
<form action="#">
<span style="font-weight:bold;">Year :</span>
<select id="year >
<option value="">Select Year</option>
<option value="0">Select All</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br />
<br />
<span style="font-weight:bold;">Faculty:</span>
<select id="faculty" onchange="">
<option value="">Select Faculty</option>
<option value="0">All Faculty</option>
<option value="1">ART</option>
<option value="2">Engineering</option>
</select>
<span style="font-weight:bold;">Major:</span>
<select id="marker" onchange="">
<option value="">Select Major</option>
<option value="0">All Major</option>
<option value="eng">English</option>
<option value="thai">Thai</option>
<option value="civil">Civil</option>
<option value="foot">Foot</option>
</select>
<input type="button" value="Search" onclick="startRequest()" />
อันนี้ส่วน PDF ครับ เลือกข้อมูลออกได้แค่ click แล้วออก หาตัวอย่างมาแก้เอา แต่ก็ไม่รู้จะไปใส่ใน listbox
ให้เลือกอย่างไร ครับ T_T
<html>
<head>
<title>Report</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["Year"],1);
$this->Cell(30,6,$eachResult["Art English"],1);
$this->Cell(55,6,$eachResult["Art Thai"],1);
$this->Cell(25,6,$eachResult["Civil Engineering"],1);
$this->Cell(20,6,$eachResult["Foot Engineering"],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(30,6,$eachResult["Year"],1);
$this->Cell(30,6,$eachResult["Art English"],1);
$this->Cell(55,6,$eachResult["Art Thai"],1);
$this->Cell(25,6,$eachResult["Civil Engineering"],1);
$this->Cell(20,6,$eachResult["Foot Engineering"],1);
$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('Year','Art English','Art Thai','Civil Engineering','Food Engineering');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("namelist");
$strSQL = "SELECT * FROM namelist";
$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 1 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
//*** Table 2 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);
//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output("namelist/MyPDF.pdf","F");
?>
PDF Created Click <a href="namelist/MyPDF.pdf">here</a> to Download
</body>
</html>
ช่วยดูหน่อยนะครับ ขอบคุณมากครับTag : - - - -
Date :
2009-12-11 00:43:40
By :
Sacrifice
View :
1305
Reply :
0
Load balance : Server 03