Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: fpdf error

  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    fpdf error

    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]

  • #2
    m1l
    m1l is offline
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • Users who have thanked m1l for this post:

    cswart777 (09-03-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thank you very much, it worked

  • #4
    New Coder
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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);

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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 Code:
    <?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
    }

  • Users who have thanked Inigoesdr for this post:

    cswart777 (09-03-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •