Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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
Php 在库fpdf上限制每页相同数量的数据_Php_Fpdf - Fatal编程技术网

Php 在库fpdf上限制每页相同数量的数据

Php 在库fpdf上限制每页相同数量的数据,php,fpdf,Php,Fpdf,我正在使用PHP和fpdf生成pdf格式的视图。我的问题是如何限制每页的数据量? 如果我有100行数据,结果是10页。所以我必须限制每页10行。 我有以下代码: <?php define('FPDF_FONTPATH', 'font/'); require_once("../../includes/initialize.php"); class PDF extends FPDF { function Header() { $this->Image("../icon/

我正在使用PHP和fpdf生成pdf格式的视图。我的问题是如何限制每页的数据量? 如果我有100行数据,结果是10页。所以我必须限制每页10行。 我有以下代码:

<?php

define('FPDF_FONTPATH', 'font/');
require_once("../../includes/initialize.php");

class PDF extends FPDF {

 function Header() {
     $this->Image("../icon/banner.jpg", 40, 10, 15);
 }

 function Footer() {
     $this->SetY(-15);
     $this->SetFont("Arial", "I", 10);
     $this->Cell(0, 10, "Page " . $this->PageNo() . "/{nb}", 0, 0, "C");
 } 

}
 $filter = $_GET["filter"];
 $value = $_GET["value"];
 if (!empty($_GET["filter"]) && !empty($_GET["value"])) {
 $query = "Select id_detail_ruang, id_ruang, id_barang, no_seri from detail_ruang
 where ".$filter." = '".$value."'";

} else {
 $query = "Select id_detail_ruang, id_ruang, id_barang, no_seri from detail_ruang";
}


$sql = mysql_query($query);
$data = array();
while ($row = mysql_fetch_assoc($sql)) {
 array_push($data, $row);
}

$judul = "LAPORAN KERUSAKAN";
$header = array(
 array("label" => "No. Detail Kerusakan", "length" => 25, "align" => "C"),
array("label" => "Kode Barang", "length" => 25, "align" => "C"),
array("label" => "Nama Barang", "length" => 50, "align" => "C"),
array("label" => "No Ruang", "length" => 50, "align" => "C")
);

$pdf = new PDF("L");
$pdf->AliasNbPages();
$pdf->AddPage();

$pdf->SetFont("Arial", "B", 7);
$pdf->Cell(0, 20, $judul, 0, 1, "C");
$pdf->SetFillColor(87, 190, 224);
$pdf->SetTextColor(33, 71, 84);
$pdf->SetDrawColor(255, 0, 25);
$pdf->SetAutoPageBreak(true, 30);
foreach ($header as $kolom) {
$pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], true);
}
$pdf->Ln();

$pdf->SetFillColor(87, 190, 224);
$pdf->SetTextColor(33, 71, 84);
$pdf->SetFont('');
$fill = false;
foreach ($data as $baris) {
 $i = 0;
foreach ($baris as $cell) {
    $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
    $i++;
}
$fill = !$fill;
$pdf->Ln();
}
$pdf->Output();
?>

由于您已经在PHP数组中查找数据,最简单的解决方案是使用:

define('TABLE_SIZE', 100);
$pages=array_chunk($data, TABLE_SIZE, true);

foreach ($page as $table) {
   foreach ($table as $baris) {
      $i = 0;
      foreach ($baris as $cell) {
         $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
         $i++;
      }
   }
   if (count($table)==TABLE_SIZE) {
      // do page break
   }
}