Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/10/2014, 05:50
fedembuj_89
 
Fecha de Ingreso: agosto-2013
Mensajes: 28
Antigüedad: 10 años, 9 meses
Puntos: 0
Sistema reservas

Buenas, necesito ayuda de una mente privilegia, me estoy volviendo loco para encontrar la buena combinación de sentencias a la hora de reservar.

Pretendo hacer un sistema de reservas donde seleccionando fecha de inicio y fecha fin me consulte todas las reservas hechas hasta el momento y interprete si es posible reservar.

tablas

MOTOS [matricula]
RES [moto] [fecha_inicio] [fecha_fin] [persona]

Código PHP:
<?php
$reserva_inicio 
$_POST['inicio'];   
$reserva_fin $_POST['fin'];  

if (
$reserva_inicio $reserva_fin 
{
  
//si las fechas son correctas coge todas las reservas
  
$reservas mysql_query("SELECT * FROM res");
    if(
$row mysql_fetch_array($reservas))
    {
      
//HAY RESERVAS, VAMOS A COMPROBARLAS TODAS
      
echo "hay reservas";
                 
$matricula mysql_query("SELECT matricula FROM motos");
                
$reservas mysql_query("SELECT * FROM res");
                
$continue TRUE;
                while(
$row mysql_fetch_array($reservas) AND $continue TRUE){

                      
//Si fecha inicio y fecha fin son menos que la reserva, se reserva
                      
if ($reserva_inicio $row[1] AND $reserva_fin $row[1]){
                         
$query "INSERT INTO res (moto, inicio, fin, persona ) VALUES ('$row[0]','$reserva_inicio', '$reserva_fin', 'Joaquin' )";
                         if(
mysql_query($query)){
                          
$continue FALSE;
                           
?>
                         <script languaje="javascript">
                            alert("Reserva hecha !");
                            location.href = "administrar.php";
                           </script>
                          <?  
                         
}   
                      }
                      if (
$fecha_fin_anterior){

                            if (
$reserva_inicio $row[1] AND $reserva_fin $row[1] AND $reserva_inicio $fecha_fin_anterior){
                                           
$query "INSERT INTO res (moto, inicio, fin, persona ) VALUES ('$row[0]','$reserva_inicio', '$reserva_fin', 'Joaquin' )";
                                           if(
mysql_query($query)){
                                                  
$continue FALSE;
                                                   
?>
                                                 <script languaje="javascript">
                                                    alert("Reserva hecha !");
                                                    location.href = "administrar.php";
                                                   </script>
                                                  <?  
                                           
}   
                                  }


                      }

                      
$fecha_fin_anterior $row[2];
                } 


    }else
//NO HAY NINGUNA RESERVA, GUARDAMOS SIN PROBLEMAS
    
{
      
$matricula mysql_query("SELECT matricula FROM motos");
        if(
$row mysql_fetch_array($matricula)){
          
//si hay motos metemos la reserva
 

           
$query "INSERT INTO res (moto, inicio, fin, persona ) VALUES ('$row[0]','$reserva_inicio', '$reserva_fin', 'Joaquin' )";
           
mysql_query($query);
           
?>
             <script languaje="javascript">
                alert("Reserva hecha !");
                location.href = "administrar.php";
               </script>
              <?  
        
}else{
            
?>
             <script languaje="javascript">
                alert("No hay motos !!");
                location.href = "administrar.php";
               </script>
              <?  

        
}
    }




}else
{
    
?>
     <script languaje="javascript">
        alert("Fechas incorrectas!");
        location.href = "administrar.php";
       </script>
      <?   
?>
}
El problema es que si no hay reservas lo mete bien, pero luego me repite reservas.

De momento estoy simulando que solo hay una moto, luego lo ampliaré a X motos.