Dhaka To

FPDF Problem Variable in Header or Footer Function Scoping Problem

FPDF Problem Variable in Header Function Scoping Problem

FPDF Problem Variable in Header Function Scoping Problem

Sometime you face scoping problem in FPDF. Example:

$party = $_POST['name'];

class PDF extends FPDF
{
  function Header()
  {
  $this->Cell(150);
  $this->Cell(30,10,$party,0,0,'C');
  }
} 

Here Party name not show because of scoping problem. 
To solve this problem using GLOBAL variable. 
Using GLOBAL you can use this variable anywhere any function. 
Example Code:


$party = $_POST['name'];

class PDF extends FPDF
{
  
  function Header()
  {
    global $party;
  $this->Cell(150);
  $this->Cell(30,10,$party,0,0,'C');
  }
} 

Hope to solve this problem. Stay with us. Happy Coding…

Read Previous

Mysql Query for Generate Serial Number in SELECT Statement

Read Next

How to Generate String Unique Number Using MD5 and Unique ID in PHP