I can not list my BD records

1

I am starting to use the FPDF library and I need to generate a PDF document with the records of my "winners" table. So far I was able to generate the PDF document but I could not list the records of my table, I would appreciate any help.

I know that in my query what I ask is that you return all the records, previously I did it with the fields "id" and "nombre_triun", I put it that way because I can not think of any more ideas and I was trying several ways to solve this but nothing, so I left the code as it was at the time of finishing one of the many tests carried out:

<?php 

    include('fpdf/fpdf.php');<br>
    include('conexion-modelo.php');

    class Conectar extends Conexion{
        public $pdoSTMT;

        public function __construct(){
            Conexion::realizandoConexion();
        }

        public function querySQL(){
            $stmt = Conexion::query("SELECT * FROM triunfadores");
            return $stmt;
        }
    }

    class PDF extends FPDF{
        function header(){
            $this->Cell(5,5,'id','C');
            $this->Cell(5,5,'nombre_triun','C');
        }
    }

    $obj = new Conectar();
    $pdf = new PDF();

    $pdf->SetFont('Arial','B',12);
    $pdf->AddPage();

    $datos = $obj -> querySQL(); 

    while($row = $datos->fetchAll(PDO::FETCH_ASSOC)){
        echo $row["id"];
    }

    $pdf->Output();
?>
    
asked by Alfredo Fernández 09.03.2018 в 01:30
source

1 answer

0

In this part of the code:

while($row = $datos->fetchAll(PDO::FETCH_ASSOC)){
    echo $row["id"];
}

You are doing a echo $row["id"] ... but with FPDF you do not write to the PDF file putting echo is written with functions like Text , Write or Cell (which you already use elsewhere in your code). Using echo could also give you additional problems (eg the famous "headers have already been sent" error).

So, instead of using echo you should use some of the functions specified above. In the example I put Cell because you are already using it for headers:

  

Warning: I have not tested this code and may contain errors

while($row = $datos->fetchAll(PDO::FETCH_ASSOC)){
    $pdf->Cell(5,5,$row["id"],'C');
}
    
answered by 09.03.2018 в 03:14