-3

For FPDF, I am trying to either add PHP variables inside a background image, e.g.

    //BACKGROUND
 if (strpos($Result, '1') !== false) {
 $Background = 'images/Cert-Sample-1.jpg';
 }

    $this->Image($Background,0,0,0,300);

or by putting the background setting inside the if statements

    //BACKGROUND
 if (strpos($Result, '1') !== false) {
    $this->Image('images/Cert-Sample-1.jpg',0,0,0,300);
 } 

But neither seems to work. Both statements are totally disregarded and the background remains blank. However, if I place echo "YES"; inside each if statement instead, this works and outputs "YES" correctly as expected.

If I remove the if statement from around the 2nd option, it also works as expected and outputs the background image.

In both these options, they're inside a function. Can PHP variables not be used inside functions? This would explain why the first option doesn't work, but not the second.

class PDF extends FPDF
{
// Page header
function Header()
{
 

 // LINES OF CODE ABOVE IS TO BE INSERTED HERE

 $this->Image('images/pdf-header.png',5,5);
    // END BACKGROUND
}
// Page footer
function Footer()
{
 $this->SetY(-20);
 //$this->Image('images/pdf-footer.jpg');
}
}

Any thoughts on how to get around this?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Henry Aspden
  • 1,863
  • 3
  • 23
  • 45
  • 2
    What does "not working" mean? Are you getting an error message? A different result from what you were hoping for? Please [edit] the question to be as specific as possible. – IMSoP Jan 14 '21 at 12:37
  • Where would `$Result` come from inside the `Header` function? – deceze Jan 15 '21 at 09:48
  • definder further up the code, pulled from SQL database. $Result is echo'ed a few lines further down so I know that it works to to speak. plus the ```echo "YES";``` seems to work inside that if statement implying the if statement works ? – Henry Aspden Jan 15 '21 at 10:17

1 Answers1

-1

Got it I had to delare Global $Result in my code before.my if statements began to allow the script to use that variable

Henry Aspden
  • 1,863
  • 3
  • 23
  • 45