我们正在做一个项目,我们需要有一个经过过滤和改进的报告。使用来自数据库的查询,我已经完成了select product,(select avg(numberPer) from ( select product,count(*) as numberPer,monthname(orderdate) as orderMonth, extract(day from orderdate) as orderDay from jobordersgroup by product,orderMonth,orderDay having orderMonth = "March" and product = "Year Book")alias)asaveragePerMonth ,monthname(orderdate) as orderMonth from joborders group by product,orderMonthhaving 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文件。
最佳答案
尝试添加以下行:
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();