我目前創建了一個可以生成從 MySQL 到 PDF 的報告的系統。我使用 FPDF 庫?,F在我想在每一頁上按限制顯示數據。例如,如果我有 100 行數據,我想這樣顯示:1) 第一個 PDF 頁面將只顯示 8 個數據 2) 其他頁面將顯示 10 個數據誰能幫我? <?php require('mem_image.php'); require_once "../../config/config.php"; require_once "../../config/check.php"; $email = $_SESSION['login_user']; $team = $_SESSION['team']; $pdf = new PDF_MemImage(); $pdf->AddPage(); $pdf->Cell(10,7,'',0,1); $pdf->SetFont('Arial','B',12); $pdf->Cell(0,10,'Project Team Overtime Report',1,1,"C"); $pdf->SetFont('Arial','',10); $pdf->Cell(20,10,'Team:',1,0); $pdf->SetFont('Arial','B',11); $user2 = mysqli_query($conn, "SELECT * FROM users WHERE email = '$email'"); while ($row = mysqli_fetch_array($user2)){ $pdf->Cell(170,10,$row['fullname'],1,1); } $pdf->SetFont('Arial','',10); $pdf->Cell(0,10,'Workers Name:',1,1,"C"); $pdf->SetFont('Arial','B',10); $pdf->Cell(20,7,'Badge ID',1,0); $pdf->Cell(170,7,'Fullname',1,1); $pdf->SetFont('Arial','',10); $user = mysqli_query($conn, "SELECT * FROM users INNER JOIN team on users.team_id = team.team_id WHERE users.team_id = '$team' AND (users.roles_id = 3 OR users.roles_id = 4)"); while ($row = mysqli_fetch_array($user)){ $pdf->Cell(20,7,$row['badgeid'],1,0); $pdf->Cell(170,7,$row['fullname'],1,1); }
1 回答

收到一只叮咚
TA貢獻1821條經驗 獲得超5個贊
您需要在while循環中使用計數器,因此它的工作方式如下:
$count = 0;
while ($row = mysqli_fetch_array($user3)){
/* put your row rendering code here */
/* ... */
if ((($count - 8) % 10) === 0) {
$pdf->AddPage();
/* put any page headers or footers here */
}
$count++;
}
這樣,您將在 8、18、28 行等之后有一個新頁面。
我認為您有一些數據(如標題)需要在每一頁(全名、徽章 ID)上重復 - 對嗎?請記住,每次添加新頁面時都需要再次呈現該標題。理想情況下,您會將頁眉代碼提取到單獨的函數中。
- 1 回答
- 0 關注
- 100 瀏覽
添加回答
舉報
0/150
提交
取消