geds13
geds13

Reputation: 191

Newbie problems with FPDF displaying values from database

I am new with FPDF and im just starting to learn,

I am trying to display a query from the database using PHP

and here are my codes.

<?php
    session_start();
    $conn = @mysql_connect("","","");
    $db = @mysql_select_db("");
    require("../pdf/fpdf.php");

$qry = "SELECT sum(order_detail.quantity*order_detail.price) as chenes, orders.date
        FROM order_detail 
        LEFT JOIN orders 
        ON order_detail.orderid=orders.serial";

mysql_set_charset("UTF8");
$result = @mysql_query($qry);
if($result === FALSE) {
    die(mysql_error()); // TODO: better error handling
}   
while ($row=mysql_fetch_array($result)){    
?>
<?php
$pdf=new FPDF();

$pdf->AddPage();

$pdf->SetFont("Arial","","13");
$pdf->Cell(0,10,"Sales Reports",0,1,"C");

$pdf->SetFont("Arial","I","10");
$pdf->Cell(0,10,"$row[chenes]",0,0,"C");
$pdf->Output();
?>

<?php } ?>

And i get this problem, FPDF error: Some data has already been output, can't send PDF file how do i fix it? i want to display values from the database, an explanation would be nice. :)

Upvotes: 0

Views: 939

Answers (2)

Diogo Silva
Diogo Silva

Reputation: 311

Try this:

define('FPDF_FONTPATH', '../pdf/font/');
require("../pdf/fpdf.php");

$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("Arial","","13");

$pdf->Cell(0,10,"Sales Reports",0,1,"C");

$pdf->SetFont("Arial","I","10");
while ($row=mysql_fetch_array($result)){    
    $pdf->Cell(0,10,$row["chenes"],0,0,"C");
}
$pdf->Output();

Upvotes: 0

Assaf Schwartz
Assaf Schwartz

Reputation: 119

try this line:

$pdf->Cell(0,10,$row['chenes'],0,0,"C");

Upvotes: 1

Related Questions