首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FPDF单元格定位

问FPDF单元格定位
EN

Stack Overflow用户
提问于 2012-10-31 16:08:04
回答 2查看 20.1K关注 0票数 5

自从我被要求为我的工作生成PDF文件后,我就开始学习FPDF。它很容易学习,但我在定制表方面遇到了一些问题。

看,下面这几行代码:

代码语言:javascript
复制
<?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文件:

​

​

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

代码语言:javascript
复制
while($u=mysql_fetch_array($t))
    {
        $pdf->Cell(50, 6, $u['location'], 1);
        $pdf->Ln();
    }

这是:Davao - Cebu Cebu - Bohol Bohol - Davao to be the Itinerary,就像这样:

​

我知道Cell()参数ln,它指示当前位置在调用之后应该去哪里,唯一的选项是:0 - to the right、1 - to the beginning of the next line和2 - below,它们没有我需要的选项。我正在经历一段艰难的时期,因为我从MySQL数据库中获取数据,所以我不知道如何根据我想要的重新定位它,因为输出在一个数组中。我对如何实现我想要的东西有什么想法吗?或者我想要的东西不能通过这个实现?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-31 16:22:12

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

代码语言:javascript
复制
while($u=mysql_fetch_array($t))
{
    $pdf->Cell(60, 6, $k, 1);
    $pdf->Cell(50, 6, $u['location'], 1);
    $pdf->Ln();
}
票数 9
EN

Stack Overflow用户

发布于 2020-06-11 22:58:47

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

代码语言:javascript
复制
<?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");
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13153612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档