Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:36:24+00:00 2026-06-08T17:36:24+00:00

My first php question… I’m using fpdf to generate pdf files. The original version

  • 0

My first php question…

I’m using fpdf to generate pdf files. The original version of the site I’m doing used a generic image on the print out. I want to change this to an id-based image.

My problem is the header with the image is declared before the query that retrieves the ID runs. This is probably easy to fix, but not with zero php-exp…

Here is my code:

<?php
require('fpdf.php');
import_request_variables("GP", "rvar_");

$prn_con = mysql_connect('localhost', 'root', '');
mysql_select_db('db');

class PDF extends FPDF{
    function Header(){
        $this->Image('../../images/logo_generic.gif',170,8,30);
        }
    }

$pdf=new PDF();
$pdf->Open();
$tok = strtok($rvar_bestellkeys,",");

while ($tok){
    $result = mysql_query('SELECT * FROM bk WHERE bestellkey = "'.$tok.'"');
    $i = 0; 
    $fCount = mysql_num_fields($result);
    while($row=mysql_fetch_row($result)){
        while ($i < $fCount){
            $fName = mysql_field_name($result, $i); 
            $$fName = trim($row[$i]);
            $i++; 
            $strcont = strlen ($$fName);
            }
            $i=0; 
    }

One of query results is the ID I’m after to include in the header() logo path.

Question:
How can I set the header() path from inside my while-loop? The loop prints out documents (single/multipage) and every page should have the logo top-right.

Thanks for help!

EDIT:
Here is the whole php script:

<?php
require('fpdf.php');
import_request_variables("GP", "rvar_");

$prn_con = mysql_connect('localhost', 'root', '');
mysql_select_db('db');

$resultsprache = mysql_query("SELECT * FROM sprachen WHERE sprache = '".$rvar_sprache."'");
while($row=mysql_fetch_row($resultsprache)){
    $fName = trim($row[2]);
    $$fName = trim($row[3]);
    }

$FileN = $tx_bestellung. '_'.date("YmdHis").'.pdf';
$title = $tx_bestellung;

class PDF extends FPDF{
    function Header(){
        $this->Image('../../images/logo_klein.gif',170,8,30);
        }
    }

 $pdf=new PDF();
 $pdf->Open();
 $pdf->AliasNbPages();
 $pdf->AddPage();
 $pdf->SetTitle($title);
 $pdf->SetFont('Arial','',8);

 $tok = strtok($rvar_bestellkeys,",");

 while ($tok){
    $result = mysql_query('SELECT * FROM bK WHERE bestellkey = "'.$tok.'"');
    $i = 0; 
    $fCount = mysql_num_fields($result);
    while($row=mysql_fetch_row($result)){
        while ($i < $fCount){
            $fName = mysql_field_name($result, $i); 
            $$fName = trim($row[$i]);
            $i++; 
            $strcont = strlen ($$fName);
            }
        $i=0; 
    }
$pdf->Cell(190,7,$tx_bestellung. " " .$tx_nr. " " .$bestellkey,0,1,'L');
    $pdf->Ln(8);
$pdf->Cell(190,5,$tx_verkaeufer,0,1);
$pdf->Cell(30,4,'ILN/GLN:',0,0);
$pdf->Cell(65,4,$vk_iln,0,1);
$pdf->Cell(30,4,$tx_firma. ':',0,0);
$pdf->Cell(65,4,$vk_firma,0,0);
$pdf->Cell(30,4,$tx_bestellnummer. ':',0,0);
$pdf->Cell(65,4,$bestellkey,0,1);
$pdf->Cell(30,4,$tx_adresse. ':',0,0);
$pdf->Cell(65,4,$vk_adresse,0,0);
$pdf->Cell(30,4,$bestelldatum. ':',0,0);
    $bestelldatum = (substr($bestelldatum, 8,2)).'.'.(substr($bestelldatum, 5, -3)).'.'.(substr($bestelldatum, 0, -6));
$pdf->Cell(65,4,$bestelldatum,0,1);
$pdf->Cell(30,4,$tx_plz. ', ' .$tx_ort. ':',0,0);
$pdf->Cell(65,4,$vk_plz.' '.$vk_ort,0,0);
.... 
$i=0; 
$result = mysql_query('SELECT * FROM bP WHERE bestellkey = "'.$tok.'"');
$fCount = mysql_num_fields($result);
$pdf->Cell(9,8,$tx_pos,1,0,'C');
$pdf->Cell(23,8,"EAN/GTIN",1,0,'C');
$pdf->Cell(43,8,$tx_bezeichnung,1,0,'C');
$pdf->Cell(10,8,$tx_groesse,1,0,'C');
$pdf->Cell(10,8,$tx_farbe,1,0,'C');
$pdf->Cell(15,8,$tx_preis,1,0,'C');
$pdf->Cell(12,8,$tx_einheit,1,0,'C');
$pdf->Cell(15,8,$tx_menge,1,0,'C');
$pdf->Cell(15,8,$tx_menge. "\n" .$tx_bestaetigt,1,0,'C');
$pdf->Cell(18,8,$tx_summe,1,1,'C');
...

$tok = strtok(",");
if($tok != ""){
    $pdf->AddPage();
}
}

mysql_close($prn_con);
$pdf->Output($FileN, 'D');

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:36:25+00:00Added an answer on June 8, 2026 at 5:36 pm

    Quick and pretty dirty, but should work:

        <?php
        require('fpdf.php');
        import_request_variables("GP", "rvar_");
    
        $prn_con = mysql_connect('localhost', 'root', '');
        mysql_select_db('db');
    
        $resultsprache = mysql_query("SELECT * FROM sprachen WHERE sprache = '".$rvar_sprache."'");
        while($row=mysql_fetch_row($resultsprache)){
            $fName = trim($row[2]);
            $$fName = trim($row[3]);
            }
    
        $FileN = $tx_bestellung. '_'.date("YmdHis").'.pdf';
        $title = $tx_bestellung;
    
        $tok = strtok($rvar_bestellkeys,",");
    
        while ($tok){
            $result = mysql_query('SELECT * FROM bK WHERE bestellkey = "'.$tok.'"');
            $i = 0; 
            $fCount = mysql_num_fields($result);
            while($row=mysql_fetch_row($result)){
    
                if ($something === true) {
                    $my_magic_id = $row['my_magic_id_column'];
                }
    
                if (isset($my_magic_id) && !class_exists('PDF')) {
                    class PDF extends FPDF{
                        function Header(){
                            global $my_magic_id;
                            $this->Image('../../images/logo_klein.gif',170,8,30);
                            }
                        }
    
                    $pdf=new PDF();
                    $pdf->Open();
                    $pdf->AliasNbPages();
                    $pdf->AddPage();
                    $pdf->SetTitle($title);
                    $pdf->SetFont('Arial','',8);
    
                }
    
                while ($i < $fCount){
                    $fName = mysql_field_name($result, $i); 
                    $$fName = trim($row[$i]);
                    $i++; 
                    $strcont = strlen ($$fName);
                    }
                $i=0; 
            }
        $pdf->Cell(190,7,$tx_bestellung. " " .$tx_nr. " " .$bestellkey,0,1,'L');
            $pdf->Ln(8);
        $pdf->Cell(190,5,$tx_verkaeufer,0,1);
        $pdf->Cell(30,4,'ILN/GLN:',0,0);
        $pdf->Cell(65,4,$vk_iln,0,1);
        $pdf->Cell(30,4,$tx_firma. ':',0,0);
        $pdf->Cell(65,4,$vk_firma,0,0);
        $pdf->Cell(30,4,$tx_bestellnummer. ':',0,0);
        $pdf->Cell(65,4,$bestellkey,0,1);
        $pdf->Cell(30,4,$tx_adresse. ':',0,0);
        $pdf->Cell(65,4,$vk_adresse,0,0);
        $pdf->Cell(30,4,$bestelldatum. ':',0,0);
            $bestelldatum = (substr($bestelldatum, 8,2)).'.'.(substr($bestelldatum, 5, -3)).'.'.(substr($bestelldatum, 0, -6));
        $pdf->Cell(65,4,$bestelldatum,0,1);
        $pdf->Cell(30,4,$tx_plz. ', ' .$tx_ort. ':',0,0);
        $pdf->Cell(65,4,$vk_plz.' '.$vk_ort,0,0);
        .... 
        $i=0; 
        $result = mysql_query('SELECT * FROM bP WHERE bestellkey = "'.$tok.'"');
        $fCount = mysql_num_fields($result);
        $pdf->Cell(9,8,$tx_pos,1,0,'C');
        $pdf->Cell(23,8,"EAN/GTIN",1,0,'C');
        $pdf->Cell(43,8,$tx_bezeichnung,1,0,'C');
        $pdf->Cell(10,8,$tx_groesse,1,0,'C');
        $pdf->Cell(10,8,$tx_farbe,1,0,'C');
        $pdf->Cell(15,8,$tx_preis,1,0,'C');
        $pdf->Cell(12,8,$tx_einheit,1,0,'C');
        $pdf->Cell(15,8,$tx_menge,1,0,'C');
        $pdf->Cell(15,8,$tx_menge. "\n" .$tx_bestaetigt,1,0,'C');
        $pdf->Cell(18,8,$tx_summe,1,1,'C');
        ...
    
        $tok = strtok(",");
        if($tok != ""){
            $pdf->AddPage();
        }
        }
    
        mysql_close($prn_con);
        $pdf->Output($FileN, 'D');
    
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Original Question Since a recent version of php added anonymous functions, is there a
I'm new to PHP first of all .. My question is once I got
This is my first question :). Im writing a little twitter app in PHP
If I have three files index.php file.php and fns.php First example (it works): index.php
I have 3 files 1) show_createtable.html 2) do_showfielddef.php 3) do_showtble.php 1) First file is
This question is relating to 2 php scripts. The first script is called pick_modcontact.php
To explain my question, let me first point to this array: <?php $_depends =
this is the first question I post in this site, so you have to
First time using this service for a question. I hope I am not asking
Hey im working on my first php site, and was hoping to get some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.