FPDF Cell Positioning

20,480

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();
}
Share:
20,480
xjshiya
Author by

xjshiya

PHP Programmer (newbie)

Updated on June 12, 2020

Comments

  • xjshiya
    xjshiya about 4 years

    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?

  • xjshiya
    xjshiya over 11 years
    I feel so stupid for not being able to think of this solution! >_< but thanks a lot! :)