5

因为我需要为我的工作生成 PDF 文件,所以我开始学习 FPDF。这很容易学习,但我在自定义表格时遇到了一些问题。

看,这些代码行:

<?php
require('fpdf/fpdf.php');
require("aacfs.php"); //database connection

$a=mysql_query("select * from reservation where reservno='00112'") or die(mysql_error());
$b=mysql_fetch_array($a);
$k=$b['fdate'];
$j=$b['acode'];

$t=mysql_query("select location from location_list where reservno='00112'") or die(mysql_error());

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',11);
$pdf->Cell(40,10,'Flight Details and Costing');
$pdf->Ln(8);
$pdf->SetFont('Arial','',10);
$pdf->Cell(60, 6, 'Aircraft', 1);
$pdf->Cell(129, 6, $j, 1);
$pdf->Ln();
$pdf->SetFont('Arial','',10);
$pdf->Cell(60, 6, 'Date', 1);
$pdf->Cell(50, 6, 'Itinerary', 1);
$pdf->Cell(19.75, 6, 'ETD', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'ETA', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Block', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Waiting', 1, 0, 'C');
$pdf->Ln();
$date = array($k, $k, $k,  '');
foreach($date as $dates)
{
    $pdf->Cell(60, 6, $dates, 1);
    $pdf->Ln();
}
while($u=mysql_fetch_array($t))
{
    $pdf->Cell(50, 6, $u['location'], 1);
    $pdf->Ln();
}

$pdf->Output();
?>

生成一个如下所示的 PDF 文件:

在此处输入图像描述

但我想做的是得到这段代码的结果:

while($u=mysql_fetch_array($t))
    {
        $pdf->Cell(50, 6, $u['location'], 1);
        $pdf->Ln();
    }

也就是: Davao - Cebu Cebu - Bohol Bohol - Davao 要在 下Itinerary,像这样:在此处输入图像描述

我知道 Cell() 参数ln,它指示调用后当前位置应该去哪里,唯一的选项是: 0 - to the right1 - to the beginning of the next line并且2 - below没有我需要的选项。我很难,因为我从 MySQL 数据库中获取数据,所以我不知道如何根据我的需要重新定位它,因为输出在一个数组中。非常感谢任何关于如何实现我想要的想法的想法。或者我想要的不能通过这个实现?

4

2 回答 2

9

在每个日期之后立即输出位置单元:

while($u=mysql_fetch_array($t))
{
    $pdf->Cell(60, 6, $k, 1);
    $pdf->Cell(50, 6, $u['location'], 1);
    $pdf->Ln();
}
于 2012-10-31T08:22:12.337 回答
0

您需要先完成每一行,然后再进行下一步。这样做并定位然后下一行并重复

<?php
require('fpdf/fpdf.php');
require("aacfs.php"); //database connection

//$a=mysql_query("select * from reservation where reservno='00112'") or die(mysql_error());
//$b=mysql_fetch_array($a);
$k='2012-08-09';
$j='RP-A009';
$t=array('Davao - Cebu', 'Cebu - Bohol', 'Bohol - Davao');

//$t=mysql_query("select location from location_list where reservno='00112'") or die(mysql_error());

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',11);
$pdf->Cell(40,10,'Flight Details and Costing');
$pdf->Ln(8);
$pdf->SetFont('Arial','',10);
$pdf->Cell(60, 6, 'Aircraft', 1);
$pdf->Cell(129, 6, $j, 1);
$pdf->Ln();
$pdf->SetFont('Arial','',10);
$pdf->Cell(60, 6, 'Date', 1);
$pdf->Cell(50, 6, 'Itinerary', 1);
$pdf->Cell(19.75, 6, 'ETD', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'ETA', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Block', 1, 0, 'C');
$pdf->Cell(19.75, 6, 'Waiting', 1, 0, 'C');
$pdf->Ln();
$date = array($k, $k, $k,  '');
$i = 0;
/*
foreach($date as $dates)
{
    $pdf->Cell(60, 6, $dates, 1);
    $pdf->Ln();
}
 */
//while($u=mysql_fetch_array($t))
foreach($t as $location)
{
        $pdf->Cell(60, 6, $date[$i], 1);
        $pdf->Cell(50, 6, $location, 1, 0);
        $pdf->Ln();
        $i++;
}
//$pdf->Output();
$pdf->Output("F","flight.pdf");
?>
于 2020-06-11T14:58:46.983 回答