Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/08/2013, 05:32
bathorz
 
Fecha de Ingreso: agosto-2013
Mensajes: 150
Antigüedad: 11 años, 6 meses
Puntos: 29
Respuesta: Pintar rango de una fecha a otra

El evento de mi prueba está entre el día 5 y 23
<input type='date'/> de html5 no funciona en todos los navegadores, yo utilicé Opera.

Código PHP:
Ver original
  1. <style type="text/css">
  2. table {
  3.     border: 1px solid #000; padding: 2px;font: 9px;
  4. }
  5. td {
  6.     border: 1px solid #999;
  7. }
  8. .rojo {
  9.     background-color: red;
  10. }
  11. .verde {
  12.     background-color: green;
  13. }
  14. .azul {
  15.     background-color: blue;
  16. }
  17. .gris {
  18.     background-color: #666;color: #aaa
  19. }
  20. </style>
  21. <form id="ver_sorteos" name="" method="post" action="">
  22.     <!--  -->
  23.     Fecha:
  24.     <?php
  25.     // fija el select en una opción
  26.     if (isset($_POST['fecha'])) {
  27.        echo "<input type='date' name='fecha' size='8' maxlength='10' value='".$_POST['fecha']."' />";
  28.     } else {
  29.        echo "<input type='date' name='fecha' size='8' maxlength='10' value='".date('Y-m-d')."' />";
  30.     }
  31.     ?>
  32.     <!--  -->
  33.     <input type="submit" name="enviar">
  34. </form>
  35. <?php
  36. /** conexión BBDD **/
  37. require_once('base/funciones/f_bd.php');
  38. conectadb('test');
  39. /** **/
  40.  
  41. if(isset($_POST['enviar'])) {
  42.    $aFechas['fecha_selec'] = $_POST['fecha'];
  43. }
  44.  
  45. /** rango de fechas de prueba **/
  46. $anio = 2013;
  47. $mes = 8;
  48. $dias_x_mes = 30;
  49.  
  50. /** Consulta BBDD **/
  51. $sql = "SELECT * FROM eventos
  52. WHERE
  53. '".$aFechas['fecha_selec']."'
  54. BETWEEN fecha_inicio AND fecha_fin;";
  55. $query = mysql_query($sql);
  56. $aRst = mysql_fetch_array($query,MYSQL_ASSOC);
  57.  
  58.  
  59. echo '<table>';
  60. for($d=1; $d <= 31; $d++) {
  61.    //Crea fechas del ciclo 2013-08-1, 2013-08-2, 2013-08-3...
  62.    $f = $anio."-".$mes."-".$d . ' ';
  63.    // le da formato de fecha
  64.    $fecha = date("Y-m-d",strtotime($f));
  65.    if (($fecha == $aFechas['fecha_selec']) && ($fecha >= $aRst['fecha_inicio']) && ($fecha <= $aRst['fecha_fin'])) {
  66.       echo "<tr><td><span class='rojo'>".$fecha."</span> fecha+evento</td></tr>";
  67.    } elseif ($fecha == $aFechas['fecha_selec']) { /** fecha seleccionada **/
  68.       echo "<tr><td><span class='azul'>".$fecha."</span> fecha</td></tr>";
  69.    } elseif (($fecha >= $aRst['fecha_inicio']) && ($fecha <= $aRst['fecha_fin'])) { /** rango evento **/
  70.       echo "<tr><td><span class='verde'>".$fecha."</span> evento</td></tr>";
  71.    } else {
  72.       echo "<tr><td><span class='gris'>$fecha</span></td></tr>";
  73.    }
  74. }
  75. echo '</table>';
  76.  
  77. ?>