Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/07/2015, 23:43
Angelito2076
 
Fecha de Ingreso: julio-2015
Mensajes: 9
Antigüedad: 8 años, 9 meses
Puntos: 0
Problemas al generar reportes creando PDF

Hola soy nuevo en el foro y en la programación de PHP y quisiera saber si alguno me podría dar una mano para resolver un inconveniente que se me presento.

El tema es así, estoy generando un reporte de los datos almacenados en la Base de datos de mysql, y en cada registro tengo un botón para que genere un PDF con los datos de dicho registro, pero me trae todos los registros que tengo almacenados, se que algo me esta faltando y no se que es.

dejo los códigos para ver si alguno me puede orientar.

este es el Reporte

Código PHP:
Ver original
  1. <?php
  2.     include("conexion.php");
  3.    
  4.     $con = mysqli_connect($host,$user,$pw) or die("No se a podido conectar con el Host" . mysqli_error($link));
  5.    
  6.     mysqli_select_db($con,$db) or die("No se pudo conectar a la Base de Datos");
  7.    
  8.     $rst_ams = mysqli_query($con,"SELECT * FROM ams ORDER BY idForm desc");
  9.    
  10.     $num_registros = mysqli_num_rows($rst_ams);
  11.    
  12.         if ($num_registros==0)
  13.     {
  14.         echo "No Se Encontraron Registros En La Base De Datos";    
  15.    
  16.         mysqli_close($con);
  17.    
  18.         exit();
  19.     }
  20. ?>
  21.  
  22.  
  23. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  27. <title>Listar Registros</title>
  28. <style type="text/css">
  29. body,td,th {
  30.     font-family: Arial, Helvetica, sans-serif;
  31. }
  32. </style>
  33. </head>
  34.  
  35. <body>
  36. <table width="75%" border="1" cellspacing="0" cellpadding="0">
  37.   <tr align="center">
  38.     <td width="11%" bgcolor="#0066FF">Formulario</td>
  39.     <td width="11%" bgcolor="#0066FF">Fecha</td>
  40.     <td width="14%" bgcolor="#0066FF">Nombre</td>
  41.     <td width="12%" bgcolor="#0066FF">Apellido</td>
  42.     <td width="10%" bgcolor="#0066FF">DNI</td>
  43.     <td width="17%" bgcolor="#0066FF">Empresa/Sector</td>
  44.     <td width="9%" bgcolor="#0066FF">Hora Ingreso</td>
  45.     <td width="16%" bgcolor="#0066FF">Hora Salida</td>
  46.     <td width="16%" bgcolor="#0066FF">&nbsp;</td>
  47.     <td width="16%" bgcolor="#0066FF">Reporte</td>
  48.   </tr>
  49.   <?php
  50.   while($fila = mysqli_fetch_array($rst_ams))
  51.   {
  52.   ?>
  53.   <tr>
  54.     <td><?php echo $fila["idForm"];?></td>
  55.     <td><?php echo $fila["Fecha"];?></td>
  56.     <td><?php echo $fila["Nombre"];?></td>
  57.     <td><?php echo $fila["Apellido"];?></td>
  58.     <td><?php echo $fila["DNI"];?></td>
  59.     <td><?php echo $fila["EmpSec"];?></td>
  60.     <td><?php echo $fila["HoraIn"];?></td>
  61.     <td><?php echo $fila["HoraSa"];?></td>
  62.     <td></td>
  63.     <td><form action="pdf_ams.php" method="post" name="reporte">
  64.               <input name="clave" type="hidden" value="<?php echo $fila["idForm"];?>" />
  65.               <input name="Fecha" type="hidden" value="<?php echo $fila["Fecha"];?>" />
  66.               <input name="Nombre" type="hidden" value="<?php echo $fila["Nombre"];?>" />
  67.               <input name="Apellido" type="hidden" value="<?php echo $fila["Apellido"];?>" />
  68.               <input name="DNI" type="hidden" value="<?php echo $fila["DNI"];?>" />
  69.               <input name="EmpSec" type="hidden" value="<?php echo $fila["EmpSec"];?>" />
  70.               <input name="Tarea" type="hidden" value="<?php echo $fila["Tarea"];?>" />
  71.               <input name="HoraIn" type="hidden" value="<?php echo $fila["HoraIn"];?>" />
  72.               <input name="HoraSa" type="hidden" value="<?php echo $fila["HoraSa"];?>" />
  73.                   <input type="submit" value="Generar" alt="cambio" title="Generar Reporte PDF"/>
  74.                 </form></td>
  75.   </tr>
  76.     <?php
  77.   }
  78.   ?>
  79. </table>
  80. </body>
  81. </html>

y este es el código para el PDF

Código PHP:
Ver original
  1. <?php
  2. require("../fpdf/fpdf.php");
  3. include("conexion.php");
  4.  
  5. $pdf = new FPDF();
  6. $pdf->AddPage();
  7. $pdf->SetFont('Arial','',8);
  8. $pdf->Image('../graphic/milogo.jpg',10,10,35,8,'JPG');
  9. $pdf->Cell(90,8,'',0);
  10. $pdf->Cell(10,8,'XXXX',0);
  11. $pdf->Cell(50,8,'',0);
  12. $pdf->Cell(10,8,'',0);
  13. $pdf->Cell(30,8,'',0);
  14. $pdf->Ln(8);
  15. $pdf->Cell(69,5,'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',0);
  16. $pdf->Cell(52,5,'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',0);
  17. $pdf->Cell(69,5,'',0);
  18. $pdf->Ln(5);
  19. $pdf->Cell(42,5,'',0);
  20. $pdf->Cell(106,5,'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',0);
  21. $pdf->Cell(42,5,'',0);
  22. $pdf->Ln(10);
  23. //CONSULTA
  24. $con = mysqli_connect($host,$user,$pw) or die("No se a podido conectar con el Host" . mysqli_error($link));
  25.    
  26.     mysqli_select_db($con,$db) or die("No se pudo conectar a la Base de Datos");
  27.    
  28.     $rst_ams = mysqli_query($con,"SELECT * FROM ams");
  29.  
  30.     while($fila = mysqli_fetch_array($rst_ams))
  31.     {
  32. $pdf->SetFont('Arial','B',6);
  33. $pdf->Cell(16,4,'Fecha',0);
  34. $pdf->Cell(158,4,'',0);
  35. $pdf->Cell(16,4,'Formulario',0);
  36. $pdf->Ln(4);
  37. $pdf->SetFont('Arial','',5);
  38. $pdf->Cell(16,4,$fila['Fecha'],0);
  39. $pdf->Cell(158,4,'',0);
  40. $pdf->Cell(16,4,$fila['idForm'],0);
  41. $pdf->Ln(5);
  42. $pdf->SetFont('Arial','B',6);
  43. $pdf->Cell(30,4,'Nombre',0);
  44. $pdf->Cell(50,4,'',0);
  45. $pdf->Cell(30,4,'Apellido',0);
  46. $pdf->Cell(50,4,'',0);
  47. $pdf->Cell(30,4,'DNI',0);
  48. $pdf->Ln(4);
  49. $pdf->SetFont('Arial','',5);
  50. $pdf->Cell(30,4,$fila['Nombre'],0);
  51. $pdf->Cell(50,4,'',0);
  52. $pdf->Cell(30,4,$fila['Apellido'],0);
  53. $pdf->Cell(50,4,'',0);
  54. $pdf->Cell(30,4,$fila['DNI'],0);
  55. $pdf->Ln(5);
  56. $pdf->SetFont('Arial','B',6);
  57. $pdf->Cell(20,4,'Empresa / Sector:',0);
  58. $pdf->SetFont('Arial','',5);
  59. $pdf->Cell(170,4,$fila['EmpSec'],0);
  60. $pdf->Ln(5);
  61. $pdf->SetFont('Arial','B',6);
  62. $pdf->Cell(20,4,'Tarea:',0);
  63. $pdf->SetFont('Arial','',5);
  64. $pdf->Cell(170,4,$fila['Tarea'],0);
  65. $pdf->Ln(5);
  66. $pdf->SetFont('Arial','B',6);
  67. $pdf->Cell(15,4,'Hora Ingreso',0);
  68. $pdf->SetFont('Arial','',5);
  69. $pdf->Cell(15,4,$fila['HoraIn'],0);
  70. $pdf->SetFont('Arial','B',6);
  71. $pdf->Cell(15,4,'Hora Salida',0);
  72. $pdf->SetFont('Arial','',5);
  73. $pdf->Cell(15,4,$fila['HoraSa'],0);
  74. $pdf->Ln(7);
  75. $pdf->SetFont('Arial','B',6);
  76. $pdf->Cell(30,4,'Firma Solicitante',0);
  77. $pdf->Cell(50,4,'',0);
  78. $pdf->Cell(30,4,'Autorizante Entrada',0);
  79. $pdf->Cell(50,4,'',0);
  80. $pdf->Cell(30,4,'Firma Salida',0);
  81. $pdf->Ln(7);
  82. $pdf->SetFont('Arial','B',6);
  83. $pdf->Cell(30,4,'___________________',0);
  84. $pdf->Cell(50,4,'',0);
  85. $pdf->Cell(30,4,'___________________',0);
  86. $pdf->Cell(50,4,'',0);
  87. $pdf->Cell(30,4,'___________________',0);
  88. $pdf->Ln(7);
  89.     }
  90. $pdf->Output();
  91. ?>