FPDF细胞定位

时间:2012-10-31 08:08:04

标签: php mysql fpdf

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

请参阅以下代码行:

<?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文件:

enter image description here

但我想要做的是获得此代码的结果:

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

是: Davao - Cebu Cebu - Bohol Bohol - DavaoItinerary之下,如下所示:enter image description here

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

2 个答案:

答案 0 :(得分:6)

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

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

答案 1 :(得分: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");
?>