Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
FPDF/PHP:页脚页面显示在下一页的底部(空白页)_Php_Mysql_Fpdf - Fatal编程技术网

FPDF/PHP:页脚页面显示在下一页的底部(空白页)

FPDF/PHP:页脚页面显示在下一页的底部(空白页),php,mysql,fpdf,Php,Mysql,Fpdf,目前,我创建了一个可以生成PDF的系统。PDF中的数据来自MySQL数据库。现在,我像这样显示数据 第一页:仅显示一个数据 第二页文字:将显示数据(每页最多3个数据) 更清楚地说,示例I有6个数据,它将显示如下: 第一页=1数据显示 第二页=3数据显示 第三页2数据显示 现在,我想添加页脚。页脚将显示在页面末尾(底部)。我已经创建了页脚 如果最后一页包含1或2个数据,则页脚将显示在该页的底部。但是如果最后一页包含3个数据,页脚将显示在下一页(空白页)的底部。我不知道是什么问题。有人能帮忙吗 下面

目前,我创建了一个可以生成PDF的系统。PDF中的数据来自MySQL数据库。现在,我像这样显示数据

第一页:仅显示一个数据

第二页文字:将显示数据(每页最多3个数据)

更清楚地说,示例I有6个数据,它将显示如下:

第一页=1数据显示

第二页=3数据显示

第三页2数据显示

现在,我想添加页脚。页脚将显示在页面末尾(底部)。我已经创建了页脚

如果最后一页包含1或2个数据,则页脚将显示在该页的底部。但是如果最后一页包含3个数据,页脚将显示在下一页(空白页)的底部。我不知道是什么问题。有人能帮忙吗

下面是我的代码

  $user3 = $conn->query("SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id 
  WHERE ot_team.team_id = '".$_GET['team']."' AND report_date BETWEEN '".$_GET["from"]."' AND '".$_GET["to"]."' ORDER BY ot_report.report_date DESC");
      $count = 0;
      while ($row = $user3->fetch(PDO::FETCH_ASSOC)){

          $pdf->SetFont('Arial','B',10);
          $pdf->Cell(20,7,'Date:',1,0);
          $pdf->Cell(67,7,date('d-m-Y',strtotime($row['report_date'])),1,0);
          $pdf->Cell(20,7,'Time:',1,0);
          $pdf->Cell(34,7,"From: ".date('H:i',strtotime($row['ot_start'])),1,0);
          $pdf->Cell(33,7,"To: ".date('H:i',strtotime($row['ot_end'])),1,1); 
          $pdf->Cell(87,7,'Before',1,0,'C');
          $pdf->Cell(87,7,'After',1,1, 'C');

          $logo = file_get_contents('../../images/faces/noimage.png');

          if(!isset($row['photo_before']) || empty($row['photo_before'])) {
            $pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 0, 'C');
          }else{ 
            $pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_before']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 0, 'C');
          }

          if(!isset($row['photo_after']) || empty($row['photo_after'])) {
            $pdf->Cell(87, 57, $pdf->MemImage($logo, $pdf->GetX()+20, $pdf->GetY()+5, 47,47,), 1, 1, 'C');
          }else{ 
            $pdf->Cell(87, 57, $pdf->MemImage(base64_decode($row['photo_after']), $pdf->GetX()+21, $pdf->GetY()+2, 45,53,), 1, 1, 'C');
          }

          if ($row['time_photo_before'] == null){
            $pdf->Cell(87,7,'-',1,0, 'C');
          }else{
            $pdf->Cell(87,7,$row['time_photo_before'],1,0, 'C');
          }

          if ($row['time_photo_after'] == null){
            $pdf->Cell(87,7,'-',1,1, 'C');
          }else{
            $pdf->Cell(87,7,$row['time_photo_after'],1,1, 'C');
          }

          if ((($count - 3) % 3) === 0) {


            $pdf->AddPage();
            $pdf->Cell(60,7,'',0,1,"C");

          }

        $count++;

      }

      $pdf->Footer($pdf->SetY(-48));

      $pdf->Footer($pdf->SetFont('Arial','B',9));
      $pdf->Footer($pdf->Cell(58,9,'Prepared by,',0,0,"C"));
      $pdf->Footer($pdf->Cell(58,9,'Verified by,',0,0,"C"));
      $pdf->Footer($pdf->Cell(58,9,'Approved by,',0,1,"C"));

  $pdf->Output();

  ?>

扩展FPDF类并修改默认页脚。任何时候启动一个新页面时,都会调用footer方法的内容,这将获得所需的结果

class PDF extends FPDF {
    function Footer() {
      $this->SetY(-48));
      $this->SetFont('Arial','B',9));
      $this->Cell(58,9,'Prepared by,',0,0,"C"));
      $this->Cell(58,9,'Verified by,',0,0,"C"));
      $this->Cell(58,9,'Approved by,',0,1,"C"));
    }  // end of the Footer function
}  // end of the PDF class

无法回答此问题,因为原始问题中未包含所有代码。在某个地方,您可能正在创建一个FPDF实例,如我的回答所示,该对象根据您的代码命名为
$pdf
。创建页脚后,您不再需要在发布的代码中使用这些行。