tFPDF - 在 header 中显示 mySQL 个结果
tFPDF - Show mySQL results in header
我正在尝试在 tFPDF 的 header 中显示 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,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();
}
}
...
错误信息:
Notice: Undefined variable: Total in C:\xampp\...\page.php on line xx
在 CBroe
的帮助下,这是我的问题的解决方案。使用 global
.
代码:
...
function Header()
{
global $Total, $Debt;
$this->SetLeftMargin(9);
...
我正在尝试在 tFPDF 的 header 中显示 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,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();
}
}
...
错误信息:
Notice: Undefined variable: Total in C:\xampp\...\page.php on line xx
在 CBroe
的帮助下,这是我的问题的解决方案。使用 global
.
代码:
...
function Header()
{
global $Total, $Debt;
$this->SetLeftMargin(9);
...