xjshiya
xjshiya

Reputation: 925

FPDF Cell Positioning

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.

See, these lines of codes:

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

generates a PDF file that looks like this:

enter image description here

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();
    }

which is: Davao - Cebu Cebu - Bohol Bohol - Davao to be under the Itinerary, like this: enter image description here

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?

Upvotes: 5

Views: 25146

Answers (2)

James
James

Reputation: 1

You need to do each line before going to next. So do and location then next line and repeat

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

Upvotes: 0

eggyal
eggyal

Reputation: 125835

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();
}

Upvotes: 9

Related Questions