我正在尝试从 mysqli_fecth_array 打印数据,但使用 fpdf 一遍又一遍地重复写入相同的数据,我可以在代码中更改什么?

问题描述

数据库看起来像这样。我希望它打印部门,然后是 KPA

示例:

部门 3:经济发展和社区发展

KPA 1:公共安全与安保 KPA 2:志愿者和实习

但我的 KPA 一遍又一遍地显示相同。

我还将在上面的 KPA 中显示每个 KPI,

所以一定是部门内部KPA的KPI上报组织的报告

但它显示如图

enter image description here

KPA
kpa_id (key)
kpa_name
部门 ID
部门
kpa_id (key)
kpa_name
部门 ID
<?PHP
    require('fpdf/fpdf.PHP');
    include('../private/shared/connect.PHP');
    
    
    class PDF extends FPDF
    {
    // Page header
    function Header()
    {
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(400);
        // Title
        // Line break
        $this->Ln(20);
    }
    
    
    // Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}','C');
    }
    
    function ChapterTitle($num,$label)
    {
        // Arial 12
        $this->SetFont('Arial','',16);
        // Background color
        $this->SetFillColor(200,220,255);
        // Title
        $this->Cell(0,6,"Department $num : $label",1,'L',true);
        // Line break
        $this->Ln(4);
    }
    
    function KPATitle($num,14);
        // Background color
        $this->SetFillColor(255,214,221);
        // Title
        $this->Cell(0,"KPA $num : $label",true);
        // Line break
        $this->Ln(4);
    }
    
    function ChapterBody($file)
    {
        // Read text file
        $txt = file_get_contents($file);
        // Times 12
        $this->SetFont('Times',16);
        // Output justified text
        $this->MultiCell(0,5,$txt);
        // Line break
        $this->Ln();
        // Mention in italics
        $this->SetFont('','I');
        $this->Cell(0,'(end of excerpt)');
    }
    
    
    
    }
    
    // Instanciation of inherited class
    $pdf = new PDF();
    $pdf->AliasNbPages();
    // Insert a logo in the top-left corner at 300 dpi
    $pdf->AddPage();
    $pdf->Image('img/logo.png',50,50);
    $pdf->SetFont('Times',14);
    // Then put a blue underlined link
    $pdf->SetTextColor(0,255);
    $pdf->SetFont('',40);
    $pdf->Write(180,'City Of Windhoek','http://www.windhoekcc.org');
    $pdf->Ln(0);
    $pdf->Write(225,'Annual Report','');
    $pdf->AddPage();
    $pdf->SetTextColor(0,90);
    $pdf->SetFont('Times',12);
        // code...
    for ($i=0; $i < 11; $i++) { 
    // Get Department
    $sqlq = "SELECT * FROM `department` WHERE department_id = $i";
    $result=MysqLi_query($conn,$sqlq);
    // Return the number of rows in result set
    $rowcount=MysqLi_num_rows($result);
    if($result->num_rows > 0){
        $row = MysqLi_fetch_assoc($result);    
        $pdf->Cell(0,$pdf->ChapterTitle($i,$row['department_name']),1);
    
        $sql="SELECT kpa_id FROM kpa WHERE department_id = $i";
        $result1=MysqLi_query($conn,$sql);
        $row1=MysqLi_num_rows($result1);
    
        if($result1->num_rows > 0){
        for ($x=1; $x <= $row1; $x++){ 
        // get KPAs per Department
        $sql2 = "SELECT kpa_name FROM kpa WHERE department_id = $i";
        $result2=MysqLi_query($conn,$sql2);
        $rowcount1=MysqLi_num_rows($result2);
    
        $r = MysqLi_fetch_array($result2);
        $pdf->Cell(0,$pdf->KPATitle($x,$r['kpa_name']),1);
        }
    }
    $pdf->AddPage();
    }}
    $pdf->Output();
    ?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)