Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to show results of mysql in header in tFPDF. So far, i have manage to create the pdf but when i am trying to add the sql data to display, i am getting error.

My code:

...
$count = "SELECT
             SUM(app_price_out) AS Outcome,
             SUM(app_price_in) AS Income,
             SUM(app_price) AS Turnover
          FROM tblappointment";

foreach($connection->query($count) as $row) {
    $Outcome= $row['Outcome'];
    $Income= $row['Income'];
    $Turnover= $row['Turnover'];
}

$Total = $Income - $Outcome;
$Debt =  $Turnover - $Income;

class PDF extends tFPDF
{
// Page header
function Header()
{
   $this->SetLeftMargin(9);
   $this->AddFont('Calibri','','Calibri.ttf',true);
   $this->SetFont('Calibri','',9);
   $this->Cell(236,12,'Expenses',0,0);
   $this->Cell(18,6,'Total:',0,0,'R');
   $this->Cell(25,6,number_format($Total,0,",","."),0,0,'R');   ===> Error Line at $Total
   $this->Cell(18,6,'Debt:',0,0,'R');
   $this->Cell(25,6,number_format($Debt,0,",","."),0,0,'R');   ===> Error Line at $Debt
   $this->ln();
}
}
...

Error message:

Notice: Undefined variable: Total in C:xampp...page.php on line xx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
165 views
Welcome To Ask or Share your Answers For Others

1 Answer

With the help of CBroe, here is the solution to my problem. Use global.

The code:

...
function Header()
{
   global $Total, $Debt;  
   $this->SetLeftMargin(9);
   ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...