Good morning. Someone who can explain or help me how to export in pdf the records of each row in mysql

0

This is the code that generates the query of the entire table

  $sql = "SELECT * FROM mitabla";
  $query = mysqli_query($con, $sql) or die (mysqli_error($con));
  $item = 0;
  while($row = mysqli_fetch_array($query)){
     $item = $item+1;
  }
    
asked by luis pacheco 20.08.2016 в 09:50
source

2 answers

2

There are several libraries in PHP to generate pdf documents.

With link for example, it would be as simple as the following code:

<?php
require('fpdf.php');

$con = new mysqli("localhost", "my_user", "my_password", "my_db");

/* verificar la conexión */
if (mysqli_connect_errno()) {
    printf("Falló la conexión: %s\n", $mysqli->connect_error);
    exit();
}

$x = $y = 10;                    // Inicializamos x e y
$pdf = new FPDF();              // Creamos el objeto pdf
$pdf->AddPage();                // Añadimos la primera página
$pdf->SetFont('Arial','B',16);  // Seleccionamos el tipo de fuente
$pdf->SetXY($x,$y);             // Vamos a la posición x=10, y=10

$sql = "SELECT * FROM mitabla";
$query = mysqli_query($con, $sql) or die (mysqli_error($con));
$item = 0;
while($row = mysqli_fetch_array($query))
{

  $pdf->Cell(40,10,$row[1]); // Imprimimos el resultado del primer campo
  $y = $y + 10;              // Bajamos la posición en 10 puntos
  $pdf->SetY($y);            // para escribir la siguiente línea 
  $item = $item+1;
}

$pdf->Output();
?>
    
answered by 20.08.2016 в 11:26
0

You should give us some more information to know what you are working with, but I would recommend FPDF, it is a very good library, we use it and you learn how to use it (it is very simple), you generate very good PDFs.

  

I leave here the link to your website link

    
answered by 20.08.2016 в 11:26