【问题标题】:fpdf printing cell table verticallyfpdf 垂直打印单元格表
【发布时间】:2013-02-06 06:09:58
【问题描述】:

我有这个来自mysql数据库的数据:

使用此代码:

<?php
require('fpdf/fpdf.php');
require("aacfs.php");

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 8);
$locquery=mysql_query("select * from ptr where reservno = '0000187' group by ptr_id asc") or die(mysql_error());

while($locrow=mysql_fetch_array($locquery))
{
    $pdf->Cell(30, 6, $locrow['location'], 1, 0, 'C');
}
$pdf->Ln();
$fquoquery=mysql_query("select distinct fquo_id as 'fquo_id' from passengers where reservno = '0000187' group by pass_id asc") or die(mysql_error());
while($fquorow=mysql_fetch_array($fquoquery))
{
    $fquo=$fquorow['fquo_id'];
    $passquery=mysql_query("select * from passengers where fquo_id = '$fquo' group by pass_id asc") or die(mysql_error());
    while($passrow=mysql_fetch_array($passquery))
    {
        $pdf->Cell(30, 6, $passrow['pass_name'], 1, 0, 'C');
    }
    $pdf->Ln();
}
$pdf->Output();
?>

我正在尝试使用此输出生成 pdf:

但是我得到了这个错误的输出:

如何使用 fpdf 实现所需的输出?请帮帮我!

【问题讨论】:

    标签: cell fpdf


    【解决方案1】:

    关于如何实现这一点,我可以为您提供的最佳示例是调整以下查询和变量以满足您的需求:

    <?php
    
    
    require('fpdf.php');
    
    //Connect to your database
    include("conectmysql.php");
    
    //Create new pdf file
    $pdf=new FPDF();
    
    //Disable automatic page break
    $pdf->SetAutoPageBreak(false);
    
    //Add first page
    $pdf->AddPage();
    
    //set initial y axis position per page
    $y_axis_initial = 25;
    
    //print column titles
    $pdf->SetFillColor(232,232,232);
    $pdf->SetFont('Arial','B',12);
    $pdf->SetY($y_axis_initial);
    $pdf->SetX(25);
    $pdf->Cell(30,6,'CODE',1,0,'L',1);
    $pdf->Cell(100,6,'NAME',1,0,'L',1);
    $pdf->Cell(30,6,'PRICE',1,0,'R',1);
    
    $y_axis = $y_axis + $row_height;
    
    //Select the Products you want to show in your PDF file
    $result=mysql_query('select Code,Name,Price from Products ORDER BY Code',$link);
    
    //initialize counter
    $i = 0;
    
    //Set maximum rows per page
    $max = 25;
    
    //Set Row Height
    $row_height = 6;
    
    while($row = mysql_fetch_array($result))
    {
    //If the current row is the last one, create new page and print column title
    if ($i == $max)
    {
        $pdf->AddPage();
    
        //print column titles for the current page
        $pdf->SetY($y_axis_initial);
        $pdf->SetX(25);
        $pdf->Cell(30,6,'CODE',1,0,'L',1);
        $pdf->Cell(100,6,'NAME',1,0,'L',1);
        $pdf->Cell(30,6,'PRICE',1,0,'R',1);
    
        //Go to next row
        $y_axis = $y_axis + $row_height;
    
        //Set $i variable to 0 (first row)
        $i = 0;
    }
    
    $code = $row['Code'];
    $price = $row['Price'];
    $name = $row['Code'];
    
    $pdf->SetY($y_axis);
    $pdf->SetX(25);
    $pdf->Cell(30,6,$code,1,0,'L',1);
    $pdf->Cell(100,6,$name,1,0,'L',1);
    $pdf->Cell(30,6,$price,1,0,'R',1);
    
    //Go to next row
    $y_axis = $y_axis + $row_height;
    $i = $i + 1;
    }
    
    mysql_close($link);
    
    //Send file
    $pdf->Output();
    ?>
    

    【讨论】:

      猜你喜欢
      • 2017-07-12
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 2021-12-01
      • 1970-01-01
      相关资源
      最近更新 更多