FPDF单元格定位 [英] FPDF Cell Positioning

查看:72
本文介绍了FPDF单元格定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我需要为工作生成PDF文件以来,我就开始研究FPDF.这很容易学习,但是自定义表遇到了一些问题.

I've started to study FPDF since I was required to generate a PDF file for my work. It was easy to learn but I've encountered some problems with customizing tables.

请参阅以下几行代码:

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

generates a PDF file that looks like this:

但是我要做的是得到以下代码的结果:

But what I want to do is to have the result of this code:

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

是: Davao - Cebu Cebu - Bohol Bohol - Davao 置于Itinerary下,如下所示:

which is: Davao - Cebu Cebu - Bohol Bohol - Davao to be under the Itinerary, like this:

我知道Cell()参数ln,该参数指示调用后当前位置应该到达的位置,唯一的选项是:0 - to the right1 - to the beginning of the next line2 - below,其中没有我需要的选项.我很难过,因为我从MySQL数据库中获取数据,所以我不知道如何根据我的期望重新定位数据,因为输出位于数组中.任何有关如何实现自己想要的目标的想法都将受到赞赏.还是我不能通过这个实现?

I'm aware of the Cell() parameters ln which indicates where the current position should go after the call and the only options are: 0 - to the right, 1 - to the beginning of the next line and 2 - below which doesn't have the option I need. I'm having a hard time 'cause I fetch the data from MySQL database so I don't know how to reposition it according to what I desire since the outputs are inside an array. Any ideas on how I can achieve what I want is greatly appreciated. Or what I want can't be achieved through this?

推荐答案

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

Output the location cells immediately after each date:

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

这篇关于FPDF单元格定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆