从 fpdf 中的查询呈现数据

render data from query in fpdf

我正在使用 fpdf 生成报告,但在生成 pdf 并从查询中呈现数据时,所有记录都出现在相同的位置,在 $pdf->SetXY

中一个接一个地显示

如何呈现 pdf 中的数据,每条记录一条一条地显示在另一条下方?这是我的代码: 数据的呈现在代码的末尾使用 while 结构

<?
require("bd_codigo_conectar.php");
date_default_timezone_set("America/Caracas");
require 'fpdf/fpdf.php';

class PDF extends FPDF
{
        function Header()
        {
            $this->Image('img/logo.png', 5, 5, 30 );
            $this->SetFont('Arial','B',15);
            $this->Cell(30);
            $this->Cell(140,10, utf8_decode('REPORTE DE INGRESOS POR FECHAS'),0,0,'C');
            $this->Ln(20);
        }

        function Footer()
        {
            $this->SetY(-15);
            $this->SetFont('Arial','I', 8);
            $this->Cell(0,10, 'Pagina '.$this->PageNo().'/{nb}',0,0,'C' );
        }       
}

$fini=$_GET["fini"];
$ffin=$_GET["ffin"];

$qr=mysql_query("SELECT DATE_FORMAT(fecha, '%d/%m/%Y') as fecha, count(id) as cantidad_premios FROM sorteo GROUP BY DATE_FORMAT(fecha, '%d/%m/%Y')") or die(mysql_error());



    $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();

    $pdf->SetFillColor(232,232,232);
    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(190,8,utf8_decode('1) FECHAS'),1,1,'L',3);

    $pdf->SetFont('Arial','',10); 
    $pdf->Cell(190,28,"",1,0,'L');


    $pdf->SetXY(21,45);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(95,5,utf8_decode("Fecha Inicio: "),0,0,'L');
    $pdf->SetXY(44,45);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(25,5,date("d-m-Y", strtotime($fini)),0,0,'L');

    $pdf->SetXY(25,52);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(95,5,utf8_decode("Fecha Fin: "),0,0,'L');
    $pdf->SetXY(44,52);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(95,5,date("d-m-Y", strtotime($ffin)),0,0,'L');

    $pdf->SetXY(10,66);
    $pdf->SetFillColor(232,232,232);
    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(190,8,'2) TOTALES:',1,1,'L',1);

    $pdf->SetXY(10,74);

    $pdf->SetFont('Arial','',10); 
    $pdf->Cell(190,28,"",1,0,'L');

    $pdf->SetXY(28,81);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(95,5,'Total premios',0,0,'L');
    $pdf->SetXY(58,81);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(25,5,'Fecha',0,0,'L');

    $ver == 90;

 while($record=mysql_fetch_array($qr)){


    $pdf->SetXY(37,90);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(95,5,$record["cantidad_premios"],0,0,'L');
    $pdf->SetXY(54,90);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(25,5,$record["fecha"],0,0,'L');

    $ver = $ver + 10;

  }




    $pdf->Output();


?>

在 while 循环的底部添加:

$pdf->Ln();  // new line

这会将指针移动到下一行的开头。您修改后的 while 循环将如下所示:

 while($record=mysql_fetch_array($qr)){


    $pdf->SetXY(37,90);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(95,5,$record["cantidad_premios"],0,0,'L');
    $pdf->SetXY(54,90);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(25,5,$record["fecha"],0,0,'L');

    $ver = $ver + 10;
    $pdf->Ln();  // new line

  }