0

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.

5
  • Make sure you dont have an echo on mysql_table.php or connect.php Commented Apr 2, 2014 at 14:22
  • You cannot print/display/echo any output to your stream before you instantiate your PDF. Commented Apr 2, 2014 at 14:23
  • @RobertRozas mysql_table.php and connect.php has no echo.. mysql_table.php contains the class of PDF_MySQL_Table and connect.php contains the MySQL Connection. Commented Apr 2, 2014 at 14:25
  • Incidentally, while I appreciate that JOINs are deeply unfashionable, they might serve a purpose here! Commented Apr 2, 2014 at 14:25
  • @Strawberry I have an other queries where I use JOIN. This was just a test to see if it viewing the pdf report would work.. Commented Apr 2, 2014 at 14:26

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.