2012-10-31 72 views
5

我開始學習FPDF,因爲我需要爲我的工作生成一個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文件,該文件是這樣的:

enter image description here

但我想要做的就是有這個代碼的結果:

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

這是: Davao - Cebu Cebu - Bohol Bohol - Davao 是下Itinerary,就像這樣:enter image description here

我知道在Cell()參數ln這表明在當前位置應該在調用後去,而唯一的選擇是:0 - to the right1 - to the beginning of the next line2 - below,它沒有我需要的選項。因爲我從MySQL數據庫中獲取數據,所以我不知道如何根據我的需求重新定位數據,因爲輸出在數組內。我是FPDF的新手,所以請和我一起裸照。任何想法,我怎麼能達到我想要的是不勝感激。或者我想要的東西無法通過這個來實現?提前致謝!

回答

6

立即輸出位置單元,每個單元之日起:

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

我覺得不能夠認爲這個解決方案如此愚蠢! > _ <但非常感謝! :) – xjshiya