Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDF Cell Positioning

Tags:

php

mysql

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.

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?

like image 993
xjshiya Avatar asked Oct 31 '12 08:10

xjshiya


1 Answers

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();
}
like image 135
eggyal Avatar answered Sep 24 '22 21:09

eggyal