Foros del Web » Programando para Internet » PHP »

[DUPLICADO] Consultar por rango de fecha con php y mysql

Estas en el tema de [DUPLICADO] Consultar por rango de fecha con php y mysql en el foro de PHP en Foros del Web. Quiero crear un formulario de consulta soy nuevo en php y cuando quiero realizar las pruebas me sale el siguiente error. Warning: mysql_fetch_array() expects parameter ...
  #1 (permalink)  
Antiguo 13/01/2016, 18:08
 
Fecha de Ingreso: enero-2016
Mensajes: 19
Antigüedad: 8 años, 3 meses
Puntos: 0
Mensaje [DUPLICADO] Consultar por rango de fecha con php y mysql

Quiero crear un formulario de consulta soy nuevo en php y cuando quiero realizar las pruebas me sale el siguiente error.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ResumenVenta\Pruebas\fechas.php on line 60
No existen registros para el rango de esas fechas

mis fechas en mysql los tengo como YYYY-MM-DD y en las consulta quiero que aparezcas DD-MM-YY

Código PHP:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title></title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <link type="text/css" href="css/sunny/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
  8. <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
  9. <script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
  10. <script type="text/javascript">
  11.  
  12. $(function() {
  13. $( ".datepicker" ).datepicker();
  14. });
  15. </script>
  16. <body>
  17. <form id="form" name="form" method="post">
  18. Fecha Inicio:
  19. <input type="text" name="fechaIni" class="datepicker">
  20. <br>
  21. Fecha Final:
  22. <input type="text" name="fechaFin" class="datepicker">
  23. <br>
  24. <input type="submit" value="Consultar">
  25. </form>
  26. <h1>Consultas</h1>
  27.  
  28. <?php
  29. function js2PhpTime($jsdate){
  30. if(preg_match('@(\d+)/(\d+)/(\d+)\s+(\d+):(\d+)@', $jsdate, $matches)==1){
  31. $ret = mktime($matches[4], $matches[5], 0, $matches[1], $matches[2], $matches[3]);
  32. //echo $matches[4] ."-". $matches[5] ."-". 0 ."-". $matches[1] ."-". $matches[2] ."-". $matches[3];
  33. }else if(preg_match('@(\d+)/(\d+)/(\d+)@', $jsdate, $matches)==1){
  34. $ret = mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
  35. //echo 0 ."-". 0 ."-". 0 ."-". $matches[1] ."-". $matches[2] ."-". $matches[3];
  36. }
  37. //return $ret;
  38. }
  39. //echo date("Y-m-d", js2PhpTime('08/02/2011'));
  40. $fechaIni="";
  41. if (isset($_POST['fechaIni'])) {$fechaIni = $_POST['fechaIni'];}
  42.  
  43. $fechaFin="";
  44. if (isset($_POST['fechaFin'])) {$fechaFin = $_POST['fechaFin'];}
  45.  
  46. //$fechaMySQLFin = $_POST[implode( '-', array_reverse( explode( '/', $fechaFin ) ) )] ;
  47. $Inicio=date("Y-m-d", js2PhpTime($fechaIni));
  48. $Final=date("Y-m-d", js2PhpTime($fechaFin));
  49. $conectar=mysql_connect('localhost','root','');
  50. if($conectar=NULL)
  51. {
  52. printf("Error al conectar a la Base de datos");
  53. }
  54.  
  55. mysql_select_db('resumenbeta');
  56. echo $fechaIni;
  57. $resultado=mysql_query("SELECT Fecha, TipoDeProduccion, Pais, Cliente FROM resumenbeta WHERE Fecha='$Inicio' BETWEEN '$Inicio' AND '$Final'");
  58.  
  59. if($row=mysql_fetch_array($resultado)){
  60. echo "<table border='1' align='center'>\n";
  61. echo "<tr><td>Fecha</td><td>TipoDeProducto</td><td>Pais</td><td>Cliente</td></tr> \n";
  62. do{
  63.  
  64. echo "<tr><td>".$row["Fecha"]."</td><td>".$row["TipoDeProducto"]."</td><td>".$row["Pais"]."</td><td>".$row["Cliente"]."</td></tr> \n";
  65. }while($row=mysql_fetch_array($resultado));
  66. echo "</table>\n";
  67. }
  68. else{
  69. echo "<center>No existen registros para el rango de esas fechas</center>";
  70. }
  71.  
  72. ?>
  73.  
  74.  
  75. </body>
  76. </html>
  #2 (permalink)  
Antiguo 13/01/2016, 18:11
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Consultar por rango de fecha con php y mysql

¿Y por qué duplicas temas?

DUPLICADO: http://www.forosdelweb.com/f18/error...mysql-1145605/
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 13/01/2016, 18:12
 
Fecha de Ingreso: enero-2016
Mensajes: 19
Antigüedad: 8 años, 3 meses
Puntos: 0
Respuesta: [DUPLICADO] Consultar por rango de fecha con php y mysql

zorry es por definir que estoy realizando y que necesito pes men

Etiquetas: consultar, fecha, formulario, html, mysql, rango, registro, select, sql
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 13:17.