I’m working on a project where parents are able to make reservations for a scheduled babysitter, and I’m having trouble finding a way to ensure that the babysitters aren’t able to accept two job reservations which would result in a time conflict. The way i’m doing it is to try and make it so that the only job requests being pulled from the database are the ones that wouldn’t cause any issues.
For my job reservations requests table, I have the following columns: Starting date, ending date, starting time, and ending time.
For example, if the babysitter is already scheduled for babysitting from November 6th to November 10th, from 10 AM to 5 PM, he/she wouldn’t be able to accept reservations for November 7th to November 15th from 12 PM to 7 PM, as there would be a time conflict in the first few days. However, he/she will be able to accept reservations from, for example, November 7th to 15th from 6 PM to 10 PM as there are no time conflicts (his/her first reservations ends before the next one starts).
So the conditions where there are no conflicts are:
- The new reservation’s ending date is before the pre-existing reservation’s starting date
- The new reservation’s starting date is after the pre-existing reservation’s ending date
OR (in the case where both reservations have overlapping dates) - The new reservation’s ending time is before the pre-existing reservation’s starting time
- The new reservation’s starting time is after the pre-existing reservations’ ending time
Some vars in my query:
$startDate //the starting date of the new job request, as a date type in my database
$endDate //the ending date of the new job request, as a date type in my database
$startTime //the starting time of the new job request, as a time type in my database
$endTime //the ending time of the new job request, as a time type in my database
The query i’ve tried to check for a date/time conflict is:
SELECT * FROM jobRequests WHERE babysitterID = ".$_SESSION['babysitterID']."
AND ( ( $endDate >= startDate OR $startDate <= endDate OR ($startDate> startDate AND $endDate < endDate) )
AND ($startTime <= endTime OR $endTime >= startTime) )";
Which gives me an error when trying to check the number of rows of the query result.
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given
I hope my question is clear enough..