Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/09/2013, 19:39
blogui91
 
Fecha de Ingreso: septiembre-2013
Ubicación: Tepic Nayarit
Mensajes: 2
Antigüedad: 10 años, 7 meses
Puntos: 0
Pregunta Guardar código fuente en variable PHP

Hola a todos, tengo un problema sobre como generar un pdf con una tabla donde los datos son generados de forma dinámica.
- Deseo hacer un reporte y se genere un PDF en este caso uso DOMPDF.
- Tengo una pagina la cual quiero convertirla en PDF pero cuando genero el PDF, éste no me reconoce el codigo en PHP y lo necesito para llenar una tabla dinamica. Ustedes dirán pero también existe FPDF y con eso se soluciona todo, pero esto no termina aquí, el problema es que algunas celdas son rellenadas de un color de forma dinamica y eso es lo que me impide usar FPDF.
Entonces se me ocurrió, guardar el código fuente(Generado del lado del cliente) de la página en una variable, y entonces poder usarla para imprimir mi pdf con DOMPDF

NO SÉ SI ME EXPLIQUE, O SI EXISTA UNA FORMA MÁS FÁCIL PARA REALIZARLO. ESTE ES EL ARCHIVO QUE QUIERO CONVERTIR A PDF:

Código PHP:
Ver original
  1. <?php
  2. include ('conexion.php');
  3.  
  4.  
  5. $query = "SELECT * FROM tbladmin";
  6. $result = mysql_query($query,$conexion);
  7. $total = mysql_num_rows($result);
  8.  
  9. $query2 = "SELECT * FROM tblusuario";
  10. $result2 = mysql_query($query2,$conexion);
  11. $total = mysql_num_rows($result2);
  12.  
  13.  
  14. ?>
  15. <html>
  16.  
  17. <head><title></title>
  18. <script src='../js/jquery.js'> </script>
  19. <link href="../css/estilo.css" rel="stylesheet" type="text/css" />
  20.  
  21. </head>
  22. <body>
  23.  
  24.              <h2> Lista de usuarios </h2>
  25.                
  26.                 <br />
  27.                 <div class="datagrid">
  28.                 <table class="tblDatosUsuario">
  29.                     <thead>
  30.                         <tr>
  31.                             <th>Color</th>
  32.                             <th>Nombre</th>
  33.                             <th>Contrase&ntilde;a</th>
  34.                             <th>Capturas </th>
  35.                             <th>% </th>
  36.                            
  37.                         </tr>
  38.                     </thead>
  39.                     <tbody>
  40.                     <?php while($row = mysql_fetch_array($result)) {
  41.                          $e = "SELECT COUNT(*) FROM tblusuario WHERE txtCaptura='".$row['txtUsuario']."'";
  42.                          $resultado = mysql_query($e,$conexion);
  43.                          $val = mysql_fetch_array($resultado);
  44.                        
  45.                         ?>
  46.                     <tr>
  47.                             <td bgcolor="<?php echo $row['txtColor'] ?>"> </td>
  48.                             <td> <?php echo $row['txtUsuario']?></td>
  49.                             <td>*******</td>
  50.                             <td> <?php echo $val[0];?>  </td>
  51.                             <td> <?php echo ($val[0]*100)/$total?>% </td>
  52.                            
  53.                         </tr>
  54.                     <?php  } ?>    
  55.                         <tr class="alt">
  56.                             <td> </td>
  57.                             <td> </td>
  58.                             <td> Total de registros capturados </td>
  59.                             <td> <?php echo $total;?> </td>
  60.                             <td> 100% </td>
  61.                         </tr>
  62.                 </tbody>
  63. </table>
  64.  
  65. </body>
  66. </html>
  67. <!-- ESTA ES LA PAGINA QUE INTENTO CONVERTIR A PDF -->

Y ESTE ARCHIVO ES EL QUE CREA EL PDF
Código PHP:
Ver original
  1. <?php
  2. //include ('../php/seccion_usuarios.php');
  3. include ('../php/conexion.php');
  4. include ('../dompdf/dompdf_config.inc.php');
  5.  
  6. $html = file_get_contents("../php/seccion_usuarios.php");
  7.  
  8.  
  9. $dompdf = new DOMPDF();
  10. $dompdf -> load_html($html);
  11. $dompdf->render();
  12. $dompdf ->stream("Reporte semestral.pdf");
  13. exit();
  14. ?>
EL PROBLEMA ES QUE SIGUE SIN RECONOCERME EL CODIGO PHP :(
En chrome, entro a seccion_usuarios.php y me aparece todo normal, veo el codigo fuente y veo esto:

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.  
  3. <script src='../js/jquery.js'> </script>
  4. <link href="../css/estilo.css" rel="stylesheet" type="text/css" />
  5.  
  6. </head>
  7.  
  8.              <h2> Lista de usuarios </h2>
  9.                
  10.                 <br />
  11.                 <div class="datagrid">
  12.                 <table class="tblDatosUsuario">
  13.                     <thead>
  14.                         <tr>
  15.                             <th>Color</th>
  16.                             <th>Nombre</th>
  17.                             <th>Contrase&ntilde;a</th>
  18.                             <th>Capturas </th>
  19.                             <th>% </th>
  20.                            
  21.                         </tr>
  22.                     </thead>
  23.                     <tbody>
  24.                                         <tr>
  25.                             <td bgcolor="#FF00FF"> <a href="#">  </a></td>
  26.                             <td> admin</td>
  27.                             <td>*******</td>
  28.                             <td> 5  </td>
  29.                             <td> 55.5555555556% </td>
  30.                            
  31.                         </tr>
  32.                                         <tr>
  33.                             <td bgcolor="#E81010"> <a href="#">  </a></td>
  34.                             <td> jsantana</td>
  35.                             <td>*******</td>
  36.                             <td> 2  </td>
  37.                             <td> 22.2222222222% </td>
  38.                            
  39.                         </tr>
  40.                                         <tr>
  41.                             <td bgcolor="#3FC718"> <a href="#">  </a></td>
  42.                             <td> csantana</td>
  43.                             <td>*******</td>
  44.                             <td> 1  </td>
  45.                             <td> 11.1111111111% </td>
  46.                            
  47.                         </tr>
  48.                                         <tr>
  49.                             <td bgcolor="#28D6D3"> <a href="#">  </a></td>
  50.                             <td> lsantana</td>
  51.                             <td>*******</td>
  52.                             <td> 1  </td>
  53.                             <td> 11.1111111111% </td>
  54.                            
  55.                         </tr>
  56.                        
  57.                         <tr class="alt">
  58.                             <td> </td>
  59.                             <td> </td>
  60.                             <td> Total de registros capturados </td>
  61.                             <td> 9 </td>
  62.                             <td> 100% </td>
  63.                         </tr>
  64.                 </tbody>
  65.  
  66. </body>
  67. </html>

QUIERO QUE MI VARIABLE OBTENGA ESTO Y LA VERDAD NO SÉ COMO.