the server must be able to reserve a classroom for 30 minutes, 1 hour or 1 hour and a half.
The database:
describes users;
'id','int(11)','NO','PRI',NULL,'auto_increment'
'username','varchar(64)','NO','',NULL,''
'email','varchar(64)','NO','',NULL,''
describes classes;
'id','int(11)','NO','PRI',NULL,'auto_increment'
'tipo','varchar(64)','NO','',NULL,''
describes reservations;
'id','int(11)','NO','PRI',NULL,'auto_increment'
'fecha','date','NO','',NULL,''
'horaInicio','time','NO','',NULL,''
'horaFin','time','NO','',NULL,''
'clases_id_id','int(11)','NO','MUL',NULL,''
'usuarios_id_id','int(11)','NO','MUL',NULL,''
My problem, the ranges for the consultations, since I know how to do it if it was from hour to hour because I would:
select * from reservas where clases_id_id=1 and fecha = "2016-05-17" and horaInicio >= "19:00" and horaFin <= "20:00";
And the result:
'4','2016-05-17','19:00:00','20:00:00','1','1'
Reservations that have already been made:
select * from reservas;
'1','2016-05-17','09:30:00','11:00:00','1','1'
'2','2016-05-17','12:00:00','13:30:00','1','1'
'3','2016-05-17','12:00:00','12:30:00','1','1'
'4','2016-05-17','19:00:00','20:00:00','1','1'
Now if I want to see the next hour, I check that there is available space:
select * from reservas where clases_id_id=1 and fecha = "2016-05-17" and horaInicio >= "20:00" and horaFin <= "21:00";
This query does not produce results.
But if now I want to reserve half an hour in half an hour, how could I do it and then do a php to generate a JSON with the content of the reservation, because if I do:
select * from reservas where clases_id_id=1 and fecha = "2016-05-17" and horaInicio >= "09:30" and horaFin <= "10:00";
I get it as free, we do not give any results and it is because of the condition of the end, since the 11 is not less than or equal to 10:00.
Does anyone think of how to solve this problem?
Thank you in advance.
Greetings