I am using fpdf to generate reports but at time to generates the pdfs and rendering the data from query, all the records appear in the same position showing one over another in $pdf->SetXY
How can I rendering the data in the pdf, each record appears one below the other? this is my code: the render of the data is at the end of the code using a while structure
<?
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();
?>
At the bottom of your while loop add:
$pdf->Ln(); // new line
which will move the pointer to the beginning of the next line. Your modified while loop will then look like this:
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
}