从fpdf中的查询中呈现数据

时间:2018-04-18 11:45:09

标签: php 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();


?>

1 个答案:

答案 0 :(得分:0)

在while循环的底部添加:

/**
 * @param <E> the type of elements in this list
 */
public interface List<E> extends Collection<E> {}

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

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