我们正在做一个项目,我们需要有一个过滤和改进的报告。使用数据库中的查询我已经完成了select product,(select avg(numberPer) from ( select product,count(*) as numberPer,
monthname(orderdate) as orderMonth, extract(day from orderdate) as orderDay from joborders
group by product,orderMonth,orderDay having orderMonth = "March" and product = "Year Book")alias)as
averagePerMonth ,monthname(orderdate) as orderMonth from joborders group by product,orderMonth
having orderMonth = "March" and product = "Year Book"
。
现在我们需要将报告视为pdf,其中一切都变得混乱。在对FPDF模板中的先前代码进行一些编辑之后,这是我的代码:
<?php
define('FPDF_FONTPATH', 'font/');
require('mysql_table.php');
class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial', '', 18);
$this->Cell(0, 6, 'Job Orders', 0, 1, 'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
//Connect to database
include("connect.php");
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//First table: put all columns automatically
$pdf->Table('select product,(select avg(numberPer) from ( select product,count(*) as numberPer,
monthname(orderdate) as orderMonth, extract(day from orderdate) as orderDay from joborders
group by product,orderMonth,orderDay having orderMonth = "March" and product = "Year Book")alias)as
averagePerMonth ,monthname(orderdate) as orderMonth from joborders group by product,orderMonth
having orderMonth = "March" and product = "Year Book"');
$pdf->Output();
?>
现在我想知道它为什么会出错:
FPDF错误:某些数据已经输出,无法发送PDF文件。
答案 0 :(得分:1)
尝试添加此行:
ob_end_clean();
在这些之间:
$pdf->Table('select product,(select avg(numberPer) from ( select product,count(*) as numberPer,
monthname(orderdate) as orderMonth, extract(day from orderdate) as orderDay from joborders
group by product,orderMonth,orderDay having orderMonth = "March" and product = "Year Book")alias)as
averagePerMonth ,monthname(orderdate) as orderMonth from joborders group by product,orderMonth
having orderMonth = "March" and product = "Year Book"');
ob_end_clean(); // HERE
$pdf->Output();