Generate PDF and Excel report from PHP

0

I have some doubts about the way PDF and Excel reports are generated from PHP. In itself is a small database (my_business) containing a table (products) with 12 records ( Link to download the database)

  

This is the code of the Index.php that I am driving

<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
        <!-- Icono -->
    <link rel="icon" type="image/png" href="img/logos/bb.ico"/>
    <title>Biblioteca</title>
    <!-- Estilos de letra -->
    <link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
    <!-- Hoja de estilo -->
      <link href="css/agency.css" rel="stylesheet">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  </head>

    <body>        
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto col-lg-9">      
      <li class="nav-item">
        <a class="nav-link js-scroll-trigger"><h3>Bienvenido </h3></a>
      </li>
      </ul>
      <ul class="col-lg-3 nav navbar-nav pull-xs-left">
      <li class="nav-item">
        <a class="pull-left" href="cerrar.php"><h3>Cerrar Sesión <i class="fa fa-user-circle" aria-hidden="true"></i></h3></a>
      </li>
    </ul>
  </div>
</nav>
        <div class="col-lg-12 text-center">
          <h2 class="section-heading">Todos los registros</h2>
            <h3 class="section-subheading text-muted">Modificar, eliminar e insertar nuevos registros</h3>
        </div>
<!-- TABLA -->
   	<div class="container">
        <table class="table display AllDataTables table-striped table-responsive">
   		   <thead style="color: #5acbf5">
            <tr>
     			<th>No</th>
     			<th>ID</th>
     			<th>Producto</th>
     			<th>Descripcion</th>
     			<th><a href="nuevo_producto1.php"><button type="button" class="btn btn-info">Nuevo</button></a></th>

    	   </tr>
        </thead>

            <tbody>
        <?php 
                          include "conexion.php";
                          $sentencia = "SELECT * FROM productos";
                          $resultado = $conexion->query($sentencia) or die (mysqli_error($conexion));
                          while($fila = $resultado->fetch_assoc()){
                            echo "<tr style='color: #7dce30'>";
                              echo "<td>"; echo $fila['no']; echo "</td>";
                              echo "<td>"; echo $fila['id_producto']; echo "</td>";
                              echo "<td>"; echo $fila['nombre']; echo "</td>";
                              echo "<td>"; echo $fila['descripcion']; echo "</td>";
                              echo "<td><a href='modificar_producto1.php?no=".$fila['no']."'> <button type='button' class= 'btn btn-success'>Modificar</button></a></td>";
                              echo "<td><a href='ElimProd.php?no=".$fila['no']."'> <button type='button' class= 'btn btn-danger'>Eliminar</button></a></td>";
                            echo "</tr>";
                          }
        ?>
      </tbody>
   	    </table>
        <thead>
          <tr>
          <th><a href=""><button type="button" class="btn btn-success">Excel</button></a></th>
          <th><a href=""><button type="button" class="btn btn-danger">PDF</button></a></th>
         </tr>
        </thead>
        </div>
<!-- FINAL DE TABLA -->

    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    

    <!-- Pie de página -->
    <footer>
        <br>
        <br>
      <div class="container">
        <div class="row">
          <div class="col-md-4">
            <span class="copyright">Copyright &copy; ProjectLibrary 2017</span>
          </div>
          <div class="col-md-4">
          </div>
          <div class="col-md-4">
            <ul class="list-inline quicklinks">
              <li class="list-inline-item">
                <a href="#">Política de privacidad</a>
              </li>
              <li class="list-inline-item">
                <a href="#">Términos de uso</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </footer>
    </body>
</html>

The "New", "Modify" and "Delete" buttons work, I just need the part of the Excel and PDF that, despite looking for information, I feel it is not clear to me yet, and I would really appreciate it a lot.

    
asked by Vicky_96HV 29.11.2017 в 19:24
source

1 answer

0

For the PDF's I've used link and it worked very well for me, it's not that complicated to use, read the documentation a bit.

For the export part to Excel link is the option I have chosen. As in the previous step, you should review the documentation.

    
answered by 29.11.2017 / 19:30
source