This is what I need:
Print the ID of employees who has availability on a certain span of time, e.g: from 28-12-2014 10:00 to 28-12-2014 11:00
These employees might be doing some other activities which are on a BD according to this picture: Table of ongoing activities
What I have:
At the moment I am comparing those dates vs the one that I need, row by row like this:
$sql_reservas="SELECT * FROM `Reservas` WHERE `ID_Empleado`= 2";
$result_reservas = mysqli_query($link,$sql_reservas);
if(mysqli_num_rows($result_reservas)>0){
foreach($result_reservas as $row_reservas ) {
ongoing_start = new DateTime("{$row_reservas['Inicio']}"); //28-12-2014 11:45 then 28-12-2014 09:45
ongoing_finish = new DateTime("{$row_reservas['Libre']}"); //28-12-2014 13:45 then 28-12-2014 10:45
new_activity_start = $_POST['date'] //28-12-2014 10:00
new_activity_finish = $_POST['date2'] //28-12-2014 11:00
If(new_activity_start<ongoing_start && new_activity_finish<ongoing_start ){
//I have space before the ongoing activities
echo $row_reservas['ID_Empleado'];
}elseif(new_activity_start>ongoing_finish && new_activity_finish>ongoing_finish) {
//I have space after the ongoing activities
echo $row_reservas['ID_Empleado'];
}else{
//overlaps with the compared one
echo "not available";
}}}
The problem:
When there is just one booking (like the ID 3 or 4 or 5...) everything works fine, BUT when there are 2 or more bookings (like with ID 2) it will still let me book the space because one of the two ongoing activities is not overlapping with the requested date
I hope you can help me with this. thanks