gpt4 book ai didi

php - 如何使用 FPDF 显示多个动态行?

转载 作者:行者123 更新时间:2023-11-28 23:22:21 25 4
gpt4 key购买 nike

一个从数据库中检索多行并且使用简单的 php 代码工作正常的页面。我想在打印/pdf View 中显示该页面(使用 fpdf)。

我使用了 FPDF 库,但它只显示数据库的第一行。我找不到解决问题的方法。

<?php
session_start();
if($_SESSION['ssn']!="") {
$search=$_SESSION['search'];
$status='cash_out';
include("connection.php");
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AliasNbPages();
$pdf->SetFont('Arial', 'B', 18);

$result= mysql_query("SELECT * FROM transaction_info WHERE cus_id='$search'&&status='$status'");
while($row = mysql_fetch_assoc($result)) {
$branch = $row['branch'];
$date = $row ['date'];
$cus_pre_bal = $row['cus_pre_bal'];
$total_bal = $row['cus_total_bal'];
$trans_bal = $row['cus_trans_bal'];

$pdf->AddPage();
$pdf->Cell(0, 20, "Cash Out Report", 1, 1, 'C');
$pdf->Cell(30, 13, " Date ", 1, 0);
$pdf->Cell(30, 13, " Branch ", 1, 0);
$pdf->Cell(42, 13, " Previous Balance ", 1, 0);
$pdf->Cell(40, 13, " Transaction Bal. ", 1, 0);
$pdf->Cell(48, 13, " Balance after Trans. ", 1, 1);

$pdf->Cell(30, 13, "{$date} ", 1, 0);
$pdf->Cell(30, 13, " {$branch} ", 1, 0);
$pdf->Cell(42, 13, " {$cus_pre_bal} ", 1, 0);
$pdf->Cell(40, 13, " {$trans_bal} ", 1, 0);
$pdf->Cell(48, 13, " {$total_bal} ", 1, 1);
}
$pdf->Output();
}

非常感谢。

最佳答案

要解决这个问题,我们必须正确使用 FPDF,并且必须在 fpdf 的右行之后开始循环。

这样解决问题:我刚开始循环

$pdf->Cell(0, 20, "Cash Out Report", 1, 1, 'C');

请注意,我们需要该行来创建静态标题行。因此,就在该行之后,我们需要开始循环:

$pdf->AddPage();
$pdf->Cell(0, 20, "Cash Out Report", 1, 1, 'C');
$result= mysql_query("SELECT * FROM transaction_info WHERE cus_id='$search'&&status='$status'");
while($row = mysql_fetch_assoc($result)){
$branch = $row['branch'];
$date = $row ['date'];
$cus_pre_bal = $row['cus_pre_bal'];
$total_bal = $row['cus_total_bal'];
$trans_bal = $row['cus_trans_bal'];

$pdf->Cell(30, 13, " Date ", 1, 0);
$pdf->Cell(30, 13, " Branch ", 1, 0);
}

关于php - 如何使用 FPDF 显示多个动态行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41014987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com