|
|
|
ช่วยทีครับ fpdf แสดงข้อมูลไม่ตรงตาราง ดึงข้อมูลจาก 2 ตาราง |
|
|
|
|
|
|
|
มันแสดงออกมาเป็น
Name1 Name2
2 2
1 1
-----------------------------------------------------------
ความต้องการที่จะให้แสดง
Name1 Name2
2 1
Code (PHP)
<html>
<head>
</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);
//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["Name1"],1);
$this->Cell(30,6,$eachResult["Name2"],1);
$this->Ln();
}
}
}
$pdf=new PDF();
//Column titles
$header=array('Name1','Name2');
//Data loading
//*** Load MySQL Data ***//
include "../conDB.php";
$datay=array();
$datax=array();
$sqlgroup="select * from tbfaculty order by Fid";
$querygroup=mysql_query($sqlgroup);
while($sqldata=mysql_fetch_array($querygroup)){
$sqlmale="select count(Sid) as num from tbstd where Fid=".$sqldata[Fid]." ";
$datax[]=$sqldata[FName];
$querymale=mysql_query($sqlmale);
$resultmale=mysql_fetch_array($querymale);
$num= $resultmale[num];
$datay[] = $num;
}
//************************//
$pdf->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
$pdf->AddFont('angsana','I','angsai.php');
$pdf->AddFont('angsana','BI','angsaz.php');
$pdf->SetFont('angsana','',12);
//$pdf->SetFont('Arial','',10);
//*** Table 1 ***//
//$pdf->Image('logo.png',80,8,33);
//$pdf->BasicTable($datax,$datay);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Ln(35);
$pdf->BasicTable($header,$datay);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2013-12-03 10:16:55 |
By :
hnu25 |
View :
869 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อยากให้มันแสดงแบบนี้ครับ
|
|
|
|
|
Date :
2013-12-03 10:36:04 |
By :
hnu25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ชื่อ คณะ ได้ึีแล้วครับ เหลือจำนวนคน จากโค้ดขาด $datay เป็นตัวแสดงจำนวนคน ไม่ทราบว่าผมต้องเขียนยังไงครับ
Code (PHP)
<html>
<head>
<title>#</title>
</head>
<body>
<?php
require('fpdf.php');
//*** Load MySQL Data ***//
include "../conDB.php";
$datay=array();
$datax=array();
$sqlgroup="select * from tbfaculty order by Fid";
$querygroup=mysql_query($sqlgroup);
while($sqldata=mysql_fetch_array($querygroup)){
$sqlmale="select count(Sid) as num from tbstd where Fid=".$sqldata[Fid]." ";
$datax[]=$sqldata[FName];
$querymale=mysql_query($sqlmale);
$resultmale=mysql_fetch_array($querymale);
$num= $resultmale[num];
$datay[] = $num;
}
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,30);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'L');
$this->Ln();
//Data
foreach ($data as $datax)
{
$this->Cell(30,7,iconv('UTF-8', 'cp874', $datax),1,0,'C');
$this->Cell(30,7,$datay,1,0,'C');
$this->Ln();
}
}
}
$pdf=new PDF();
//Column titles
$header=array('คณะ','จำนวน');
//Data loading
$pdf->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
$pdf->AddFont('angsana','I','angsai.php');
$pdf->AddFont('angsana','BI','angsaz.php');
$pdf->SetFont('angsana','',12);
//$pdf->SetFont('Arial','',10);
//*** Table 1 ***//
//$pdf->Image('logo.png',80,8,33);
//$pdf->BasicTable($datax,$datay);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->BasicTable($header,$datax);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>
|
|
|
|
|
Date :
2013-12-03 12:12:29 |
By :
hnu25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|