This is what I need:
Print the ID of employees who has availability on a certain span of time, eg: 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
what i understand, that you need to get all employee IDs in that table, that are FREE in a period of time,
what about using between
?
try this:
select ID_Empleado FROM `Reservas` WHERE
(CAST('$date' AS DATETIME) NOT BETWEEN Inicio and Libre)
AND
(CAST('$date2' AS DATETIME) NOT BETWEEN Inicio and Libre)
$date
and $date2
are values from $_POST[]
Explanation: get employee's ID that needed-start-date and needed-end-date not falling between start-date and end-date of an activity
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.