【问题标题】:FPDF Cell PositioningFPDF 单元格定位
【发布时间】:2012-10-31 08:08:03
【问题描述】:

我开始学习 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 文件:

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

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 line2 - below,它们没有我需要的选项。我很难,因为我从 MySQL 数据库中获取数据,所以我不知道如何根据我的需要重新定位它,因为输出在一个数组中。非常感谢任何关于如何实现我想要的想法的想法。还是我想要的无法通过这个实现?

【问题讨论】:

    标签: php mysql fpdf


    【解决方案1】:

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

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

    【讨论】:

    • 我为无法想到这个解决方案而感到非常愚蠢! >_
    【解决方案2】:

    您需要在进行下一行之前完成每一行。这样做并定位然后下一行并重复

    <?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");
    ?>
    

    【讨论】:

      猜你喜欢
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2011-08-20
      • 2020-05-08
      相关资源
      最近更新 更多