...

View Full Version : fpdf error



cswart777
08-31-2011, 07:12 PM
i'm trying to link a single entry into a pdf but everytime i run the script i get :
Notice: Undefined variable: row_Traceps in test.php on line 11
FPDF error: Some data has already been output, can't send PDF file
where am i going wrong i'm still learning php.
below is the script:
[CODE]
<?php require_once('Connections/traces.php');?>
<?php
mysql_select_db($database_traces, $traces);
$query_rsTraceps = "SELECT * FROM traceps WHERE id = 1";
$rsTraceps = mysql_query($query_rsTraceps, $traces) or die(mysql_error());
$row_rsTraceps = mysql_fetch_assoc($rsTraceps);
require ('fpdf.php');
$pdf = new FPDF('P', 'mm', 'A4');
$pdf -> AddPage();
$pdf -> SetFont ('Arial','B', 10);
$pdf -> Cell (40,10, $row_Traceps['id'] ,1);
$pdf -> Ln(20);
$pdf -> Cell (60,10,'Test',0,1,'C');
$pdf -> Output();
?>
[CODE]

m1l
08-31-2011, 08:12 PM
Your variable on line 5 is

$rsTraceps

and you trying to use a variable called

$row_Traceps['id']

on line 11. Change one of these to be the same as the other and it should fix your issue.

cswart777
09-01-2011, 03:11 AM
thank you very much, it worked

cswart777
09-01-2011, 07:37 AM
please can anyone assist i'm trying to create individual documents per record to save as pdf, but doesnt get past the first record.


<?php
mysql_select_db($database_traces, $traces);
$query_rsTraceps = "SELECT * FROM traceps ORDER BY sfref";
$rsTraceps = mysql_query($query_rsTraceps, $traces) or die(mysql_error());
$row_rsTraceps = mysql_fetch_assoc($rsTraceps);
$i='0';
while ($i > $row_rsTraceps) {

$i++;
}
require ('fpdf.php');
$pdf = new FPDF('P', 'mm', 'A4');
$pdf -> AddPage();
$pdf -> SetFont ('Arial','B', 10);
$pdf-> Image('traceps.jpg',10,6,50);
$pdf -> Ln(40);
$pdf -> Cell (25,5,"Reference :");
$pdf -> Cell (80,5,$row_rsTraceps['sfref'] ,1);

Inigoesdr
09-02-2011, 03:50 AM
You need to put your PDF generation in the loop, and fix your loop so you get the row each time instead of just once:

<?php

require ('fpdf.php');
require_once('Connections/traces.php');

mysql_select_db($database_traces, $traces);

$query_rsTraceps = "SELECT * FROM traceps ORDER BY sfref";
$rsTraceps = mysql_query($query_rsTraceps, $traces) or die(mysql_error());

while($row_rsTraceps = mysql_fetch_assoc($rsTraceps))
{
$pdf = new FPDF('P', 'mm', 'A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B', 10);
$pdf->Image('traceps.jpg',10,6,50);
$pdf->Ln(40);
$pdf->Cell(25,5,"Reference :");
$pdf->Cell(80,5,$row_rsTraceps['sfref'] ,1);

$pdf->Output('yourfile_' . $row_Traceps['id'] . '.pdf'); // use a unique name here if the id isn't available
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum