5

仕事用の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ファイルを生成します。

ここに画像の説明を入力してください

しかし、私がやりたいのは、このコードの結果を取得することです。

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

これは: このように、Davao - Cebu Cebu - Bohol Bohol - Davao の下にあることItineraryです:ここに画像の説明を入力してください

ln呼び出し後に現在の位置をどこに配置するかを示すCell()パラメーターを認識しており、オプションは次0 - to the rightのとおりです。必要なオプションが1 - to the beginning of the next lineあり2 - belowません。MySQLデータベースからデータをフェッチするので、出力が配列内にあるため、希望どおりにデータを再配置する方法がわかりません。私が望むことをどのように達成できるかについてのアイデアは大歓迎です。それとも、これでは達成できないことはありますか?

4

2 に答える 2

9

各日付の直後にロケーションセルを出力します。

while($u=mysql_fetch_array($t))
{
    $pdf->Cell(60, 6, $k, 1);
    $pdf->Cell(50, 6, $u['location'], 1);
    $pdf->Ln();
}
于 2012-10-31T08:22:12.337 に答える
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");
?>
于 2020-06-11T14:58:46.983 に答える