2011-10-26 4 views
-1

私はpdf形式でPHPとfpdfを使用しています。私の問題は、1ページあたりのデータ量を制限する方法です。 データが100行の場合、結果は10ページです。だから私はページあたり10行を制限する必要があります。 私はこのコードを持っている:私はSetAutoPageBreakを使用してみてくださいよライブラリーfpdfのページあたりの金額は同じです。

<?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の配列にデータを行くたので おかげ

答えて

0

、最も簡単な解決策はarray_chunk()を使用することです:

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 
    } 
} 
関連する問題