Pregunta

We're doing a project and we needed to have a report that is filtered and improved. Using a query from the database I have done itselect 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".

Now we need to view the report as a pdf which where everything went haywire. After some editing of previous code from FPDF template, here is my code:

<?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();
?>

Now I would want to know why it errors:

FPDF error: Some data has already been output, can't send PDF file.

¿Fue útil?

Solución

Try adding this line:

ob_end_clean();

Between those:

$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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top