【问题标题】:Undefined variable in FPDF. help me. mysqliFPDF 中未定义的变量。帮我。 mysqli
【发布时间】:2020-02-21 23:24:02
【问题描述】:

为什么注意:未定义的变量:datanya? 你能修好吗?这是我的代码: 我该如何解决。

require("fpdf.php");
$konek=mysqli_connect("localhost","root","","rollab");
$kode=$_GET['kode'];
$query=mysqli_query($konek,"select*from wp_jadwal where id_jadwal='.$kode.'");
$datanya =mysqli_fetch_assoc($query);

class myPDF extends FPDF{
    function headerPro(){
       $this->Ln(13);
        $this->Cell(40,5,$datanya["tanggalpemutaran"],0,0,'L');
        $this->Ln();
    }
}

【问题讨论】:

    标签: pdf fpdf


    【解决方案1】:

    您应该查看this FPDF 的常见问题解答。它适用于默认的 Header/Footer 方法,但它是同一个问题:

    5.我尝试在 Header 方法中显示一个变量,但没有打印出来。

    你必须使用 global 关键字来访问全局变量,例如:

    function Header()
    {
        global $title;
    
        $this->SetFont('Arial', 'B', 15);
        $this->Cell(0, 10, $title, 1, 1, 'C');
    }
    
    $title = 'My title';
    

    或者,您可以使用对象属性:

    function Header()
    {
        $this->SetFont('Arial', 'B', 15);
        $this->Cell(0, 10, $this->title, 1, 1, 'C');
    }
    
    $pdf->title = 'My title';
    

    【讨论】:

    • 谢谢,但我如何将它与 mysqli 连接?当我把$datanya代码放到viewTable()中的时候,也是报错
    猜你喜欢
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    相关资源
    最近更新 更多