Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] consulta con variables y fechas

Estas en el tema de consulta con variables y fechas en el foro de PHP en Foros del Web. saludos señores tengo un problema al hacer una consulta quier que me de los datos de un rango de fechas pero me da un error ...
  #1 (permalink)  
Antiguo 17/11/2015, 12:22
 
Fecha de Ingreso: octubre-2015
Ubicación: ciudad juarez
Mensajes: 90
Antigüedad: 8 años, 6 meses
Puntos: 1
consulta con variables y fechas

saludos señores tengo un problema al hacer una consulta quier que me de los datos de un rango de fechas pero me da un error

lo hice de estas dos formas pero ninguna me da los datos

Código PHP:
$tipo $_POST['tipo'];
$dato $_POST['dato'];
$inicio $_POST['inicio'];
$final $_POST['final'];
 
$query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha >='$inicio' AND  <='$final')"); 

Código PHP:
$tipo $_POST['tipo'];
$dato $_POST['dato'];
$inicio $_POST['inicio'];
$final $_POST['final'];
 
$query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha between '$inicio' AND '$final"); 
  #2 (permalink)  
Antiguo 17/11/2015, 12:32
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: consulta con variables y fechas

Cita:
pero me da un error
¿Tenemos que ejecutar mentalmente el código para adivinar el error que recibes o podrías compartirlo?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 17/11/2015, 12:35
 
Fecha de Ingreso: octubre-2015
Ubicación: ciudad juarez
Mensajes: 90
Antigüedad: 8 años, 6 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>
  #4 (permalink)  
Antiguo 17/11/2015, 12:38
 
Fecha de Ingreso: octubre-2015
Ubicación: ciudad juarez
Mensajes: 90
Antigüedad: 8 años, 6 meses
Puntos: 1
Respuesta: consulta con variables y fechas

Cita:
Iniciado por edgaralcalaserra Ver Mensaje
este es el codigo completo, lo que pasa es que al momento de hacer la consulta con la primera condicion funciona bien pero al agregar que me de la consulta con el rango de fechas no funciona me marca un error en esta linea

Código PHP:
while($row mysql_fetch_array($query)){ 

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>
  #5 (permalink)  
Antiguo 17/11/2015, 12:39
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: consulta con variables y fechas

A ver, ¿dices que obtienes un error pero muestras el código? ¿si leíste bien lo que puse?

Entiende que no podemos adivinar el error que obtienes si muestras el código.

Cita:
no funciona me marca un error en esta linea
¿Es muy complicado para ti compartir el mensaje de error que obtienes?

Si miras bien tu consulta te falta cerrar paréntesis y comillas:
Código PHP:
Ver original
  1. // MAL
  2. $query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha between '$inicio' AND '$final");
  3.  
  4. // BIEN
  5.  $query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha between '$inicio' AND '$final') ");
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 17/11/2015, 12:40
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: consulta con variables y fechas

para que las encierras en partentesis, digo no cre que sea necesario, o al menos yo no lo uso, y lo otreo es que el segundo parentesis no esta cerrado ni la comjilla simple:

Código PHP:
Ver original
  1. $query=mysql_query ("SELECT * FROM entrada WHERE ($tipo='$dato') AND (fecha between '$inicio' AND '$final')");
__________________
[email protected]
HITCEL

Etiquetas: fecha, select, sql, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:36.