问题描述
我试图在 tFPDF 的标题中显示 MysqL 的结果。到目前为止,我已经设法创建了 pdf,但是当我尝试添加要显示的 sql 数据时,出现错误。
我的代码:
...
$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);
$this->Cell(18,6,'Total:','R');
$this->Cell(25,number_format($Total,","."),'R'); ===> Error Line at $Total
$this->Cell(18,'Debt:',number_format($Debt,'R'); ===> Error Line at $Debt
$this->ln();
}
}
...
错误信息:
Notice: Undefined variable: Total in C:\xampp\...\page.PHP on line xx
解决方法
在 CBroe
的帮助下,这是我问题的解决方案。使用 global
。
代码:
...
function Header()
{
global $Total,$Debt;
$this->SetLeftMargin(9);
...