英文:
Custom footer text using TCPD php
问题
我尝试在TCPDF页脚中创建自定义文本,并放置已经从数据库中定义的变量$name
,但是一直出现错误,提示Notice: Undefined variable: name
。
public function Footer() {
// 从底部距离15毫米的位置开始
$this->SetY(-15);
// 设置字体
$this->SetFont('helvetica', 'I', 8);
$fhtml = '
<table>
<tr>
<td>用户:</td><td colspan="10"> ' . $name . '</td>
</tr>
</table>';
$this->writeHTML($fhtml, true, false, true, false, '');
}
而这个变量$name
已经在以下代码中定义:
$user = mysqli_query($conn, "SELECT * FROM users WHERE users='$users'");
$sqluser = mysqli_fetch_assoc($user);
$name = $sqluser["login"];
如何创建自定义TCPDF页脚?
英文:
I tried to make a custom text in footer TCPD and put variable that i already defined from database which is '$name'. But it keeps get error said 'Notice: Undefined variable: name'.
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
$fhtml = '
<table>
<tr>
<td>User </td><td colspan="10">: '.$name.'</td>
</tr>
</table>
';
$this->writeHTML($fhtml, true, false, true, false, '');
}
and this variable that i already defined
$user = mysqli_query($conn,"SELECT * FROM users WHERE users='$users'");
$sqluser = mysqli_fetch_assoc($user);
$name = $sqluser["login"];
How can i make a custom footer TCPDF
答案1
得分: 1
这个问题与TCPDF无关,而与PHP相关。您在类方法的范围内使用了一个全局变量。
将类方法修改为重新定义方法内的$name变量的作用域,如下所示:
public function Footer() {
global $name
....
}
英文:
This issue is not related to TCPDF but related to PHP. You are using a global variable inside the scope of the class method.
Modify the class method to redefine the scope of the $name variable inside the method as follows
public function Footer() {
global $name
....
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论