Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/11/2015, 12:35
edgaralcalaserra
 
Fecha de Ingreso: octubre-2015
Ubicación: ciudad juarez
Mensajes: 90
Antigüedad: 8 años, 7 meses
Puntos: 1
Respuesta: consulta con variables y fechas

este es el codigo completo


Código PHP:
Ver original
  1. <?php
  2. //insertamos los headers que van a generar el archivo excel
  3. header('Content-type: application/vnd.ms-excel');
  4. //en filename vamos a colocar el nombre con el que el archivo xls sera generado
  5. header("Content-Disposition: attachment; filename=consulta.xls");
  6. header("Pragma: no-cache");
  7. header("Expires: 0?");
  8. //recogemos la variable de fecha con la que limitaremos la cinsulta.
  9.  
  10. //hacemos la conexion al servidor MySql
  11. $conexion = mysql_connect ("localhost", "root", "");
  12.  mysql_select_db ("retrabajo", $conexion);
  13. //realizamos la consulta
  14. $tipo = $_POST['tipo'];
  15. $dato = $_POST['dato'];
  16. $inicio = $_POST['inicio'];
  17. $final = $_POST['final'];
  18.  $query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha between '$inicio' AND '$final");
  19.  
  20. ?>
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  22. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  23. <html xmlns="http://www.w3.org/1999/xhtml">
  24. <head>
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  26. <title>Reporte de cosulta</title>
  27. </head>
  28.  
  29. <body><!-Vamos a crear una tabla que será impresa en el archivo excel->
  30.  
  31. <!-creamos la tabla de el reporte con border 1 y los títulos->
  32. <table width="641" border="1">
  33. <tr>
  34. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Schedule</strong></th>
  35. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Estilo</strong></th>
  36. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Serie</strong></th>
  37. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Id TX</strong></th>
  38. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Linea</strong></th>
  39. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Area</strong></th>
  40. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>KVA'S</strong></th>
  41. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Numero de reloj del operador</strong></th>
  42. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Numero de reloj del reparador</strong></th>
  43. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Falla</strong></th>
  44. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Codigo</strong></th>
  45. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Fase</strong></th>
  46. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Fecha entrada</strong></th>
  47. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Comentarios entrada</strong></th>
  48. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Estatus</strong></th>
  49. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Fecha salida</strong></th>
  50. <th width="50%" style="background-color:#006; text-align:center; color:#FFF"><strong>Comentarios salida</strong></th>
  51. </tr>
  52. <?php
  53. // Un proceso repetitivo para imprimir cada uno de los registros.
  54. while($row = mysql_fetch_array($query)){
  55. echo
  56. "<tr>
  57. <td bgcolor=\"#ededed\" align=\"center\">$row[schedule]</td>
  58. <td bgcolor=\"#ededed\" align=\"center\">$row[estilo]</td>
  59. <td bgcolor=\"#ededed\" align=\"center\">$row[idtx]</td>
  60. <td bgcolor=\"#ededed\" align=\"center\">$row[linea]</td>
  61. <td bgcolor=\"#ededed\" align=\"center\">$row[area]</td>
  62. <td bgcolor=\"#ededed\" align=\"center\">$row[estilo]</td>
  63. <td bgcolor=\"#ededed\" align=\"center\">$row[kvas]</td>
  64. <td bgcolor=\"#ededed\" align=\"center\">$row[nrelojo]</td>
  65. <td bgcolor=\"#ededed\" align=\"center\">$row[nrelojr]</td>
  66. <td bgcolor=\"#ededed\" align=\"center\">$row[falla]</td>
  67. <td bgcolor=\"#ededed\" align=\"center\">$row[codigo]</td>
  68. <td bgcolor=\"#ededed\" align=\"center\">$row[fase]</td>
  69. <td bgcolor=\"#ededed\" align=\"center\">$row[fecha]</td>
  70. <td bgcolor=\"#ededed\" align=\"center\">$row[comentarioe]</td>
  71. <td bgcolor=\"#ededed\" align=\"center\">$row[estatus]</td>
  72. <td bgcolor=\"#ededed\" align=\"center\">$row[fechas]</td>
  73. <td bgcolor=\"#ededed\" align=\"center\">$row[comentarios]</td>
  74. </tr>";
  75. }
  76. ?>
  77. </table>
  78. </table>
  79. </body>
  80. </html>