Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/09/2011, 12:02
matt_1985
 
Fecha de Ingreso: enero-2011
Ubicación: /root
Mensajes: 530
Antigüedad: 13 años, 3 meses
Puntos: 61
problemas al exportar a excel

Lectores del foro tengo el siguiente problema , tengo un buscador en el cual el criterio de busqueda es la fecha , el problema es que intento implementar que los resultados que me muestre el buscador sean exportados a un formato excel , mi duda es que el parametro al archivo exportar excel lo paso bajo el parametro $GET pero no me sale ningun resultado, expongo el codigo espero puedan brindarme su ayuda .

buscar.php
Código PHP:
Ver original
  1. <?php
  2. if ($_POST['buscador']){
  3. $buscar = $_POST['palabra'];
  4. // Si está vacío
  5. if(empty($buscar)){
  6.     echo "No se han ingresado datos a Buscar";
  7. }
  8.  
  9. else{
  10.     $con=mysql_connect("localhost","xxx","xxx");
  11.     $sql = "SELECT
  12.                 unifica_proyectos.id,
  13.                 unifica_proyectos.nombreencuesta,
  14.                 unifica_proyectos.fecha,
  15.                 unifica_proyectos.rut,
  16.                 unifica_proyectos.nombreevaluador,
  17.                 unifica_proyectos.idregion,
  18.                 unifica_proyectos.coordinador,
  19.                 unifica_proyectos.mail,
  20.                 regiones.region,
  21.                 regiones.idregion
  22.                
  23.             FROM unifica_proyectos
  24.             INNER JOIN regiones ON unifica_proyectos.idregion = regiones.idregion WHERE fecha like '%$buscar%' ORDER BY id DESC";
  25.            
  26.     mysql_select_db("bd_mistery", $con);
  27.  
  28.     $result = mysql_query($sql, $con);
  29.     $total = mysql_num_rows($result);
  30.         if ($row = mysql_fetch_array($result)){
  31.             do {   
  32.                     $nombreencuesta=utf8_encode($row['nombreencuesta']);
  33.                     $fecha=$row['fecha'];  
  34.                     $fecha=date("d-m-Y",strtotime($fecha));
  35.                     $rut=$row['rut'];
  36.                     $nombreevaluador=utf8_encode($row['nombreevaluador']);
  37.                     $region=utf8_encode($row['region']);
  38.                     $coordinador=utf8_encode($row['coordinador']);
  39.                     $mail=utf8_encode($row['mail']);
  40.  
  41.                 echo "<table class=cambia-color>";
  42.                 echo "<tr>";
  43.                 echo "<td width=20%>$nombreencuesta</td>";
  44.                 echo "<td width=10%>$fecha</td>";
  45.                 echo "<td width=10%>$rut</td>";
  46.                 echo "<td width=20%>$nombreevaluador</td>";
  47.                 echo "<td width=10%>$region</td>";
  48.                 echo "<td width=10%>$coordinador</td>";
  49.                 echo "<td width=10%>$mail</td>";
  50.                 echo "</table>";
  51.                
  52.                
  53.                 }
  54.  
  55.     while ($row = mysql_fetch_array($result));
  56.  
  57.         }
  58. else {
  59. echo "No se encontraron resultados para: <b>$buscar</b>";
  60. }
  61. }
  62. }
  63. ?>
  64. <a href="exportar_excel.php?<?php echo $buscar;?>">Exportar</a>


exportar_excel.php

Código PHP:
Ver original
  1. $buscar=$_GET['palabra'];
  2.  
  3. header('Pragma: public');
  4. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past    
  5. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  6. header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
  7. header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
  8. header('Pragma: no-cache');
  9. header('Expires: 0');
  10. header('Content-Transfer-Encoding: none');
  11. header('Content-Type: application/vnd.ms-excel'); // This should work for IE & Opera
  12. header('Content-type: application/x-msexcel'); // This should work for the rest
  13. header('Content-Disposition: attachment; filename="nombre.xls"');
  14.  
  15. $conexion=mysql_connect("localhost","xxx","xxx");
  16.     $sql = "SELECT
  17.                 unifica_proyectos.id,
  18.                 unifica_proyectos.nombreencuesta,
  19.                 unifica_proyectos.fecha,
  20.                 unifica_proyectos.rut,
  21.                 unifica_proyectos.nombreevaluador,
  22.                 unifica_proyectos.idregion,
  23.                 unifica_proyectos.coordinador,
  24.                 unifica_proyectos.mail,
  25.                 regiones.region,
  26.                 regiones.idregion
  27.                
  28.             FROM unifica_proyectos
  29.             INNER JOIN regiones ON unifica_proyectos.idregion = regiones.idregion WHERE fecha='".$buscar."'";
  30.            
  31.     mysql_select_db("bd_mistery", $conexion);
  32.  
  33.     $result = mysql_query($sql, $conexion);
  34.     while($row = mysql_fetch_array($result)){
  35.        
  36.         $nombreencuesta=utf8_encode($row['nombreencuesta']);
  37.         $fecha=$row['fecha'];  
  38.         $fecha=date("d-m-Y",strtotime($fecha));
  39.         $rut=$row['rut'];
  40.         $nombreevaluador=utf8_encode($row['nombreevaluador']);
  41.         $region=utf8_encode($row['region']);
  42.         $coordinador=utf8_encode($row['coordinador']);
  43.         $mail=utf8_encode($row['mail']);
  44.            
  45. echo '<table xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
  46.   <tr>
  47.       <td>$nombreencuesta</td>
  48.        <td>$fecha</td>
  49.        <td>$rut</td>
  50.        <td>$nombreevaluador</td>
  51.        <td>$region</td>
  52.        <td>$coordinador</td>
  53.        <td>$mail</td>
  54.   </tr>
  55. </table>';
  56. }

saludos y de antemano gracias