Hi All
I’m really stuck on a problem, posted a similar question but not getting anywhere trying to figure it out.
I have a table of time slot ranges ie 9:00 - 9:30, 9:31 - 10:00, 10:01 - 10:30 etc
Someone places a booking say 30 minutes at 9:45 I need to slot in a booking slot as 9:45 - 10:15 as booked and adjust the time either side to match up one minute before ie
Slot booked at 9:45 - 10:15
9:00 - 9:30 available
9:31 - 10:00 available
10:01 - 10:30 available
After booking, row 2 is deleted as booking fills this slot fully,
row 1 finish time is 1 minute before start of booking and row 3 start time is 1 minute after booking finish time
9:00 - 9:44 available
booking 9:45 - 10:15
10:16 - 10:30 available
I’ve played around with the code but can figure it all out
// if a timeslot fall between after delete
$query = "SELECT id FROM tblServicesTimeSlotsTEST WHERE slotFromTime BETWEEN '$slotFromTime' AND '$slotToTime' AND
clientID='$clientID' AND staffID='$staffID'";
$result = mysql_query($query,$db);
$row = mysql_fetch_array($result);
$after_id = $row[id];
if($after_id!="")
{
$adjustSlotFromTime = $slotToTime + 60;
$fromTimeAdjust = date("H:i:s",$adjustSlotFromTime);
$query = "UPDATE tblServicesTimeSlotsTEST SET slotFromTime='$adjustSlotFromTime', fromTime='$fromTimeAdjust' WHERE id='$after_id' AND clientID='$clientID'";
echo("After Slot : $query<br>");
mysql_query($query,$db);
}
// if a timeslot fall between before delete
$query = "SELECT id FROM tblServicesTimeSlotsTEST WHERE slotToTime BETWEEN '$slotFromTime' AND '$slotToTime' AND
clientID='$clientID' AND staffID='$staffID'";
$result = mysql_query($query,$db);
$row = mysql_fetch_array($result);
$before_id = $row[id];
if($before_id!="")
{
$adjustSlotToTime = $slotFromTime - 60;
$ToTimeAdjust = date("H:i:s",$adjustSlotToTime);
$query = "UPDATE tblServicesTimeSlotsTEST SET slotToTime='$adjustSlotToTime', ToTime='$ToTimeAdjust' WHERE id='$before_id' AND clientID='$clientID'";
mysql_query($query,$db);
echo("Before Slot : $query<br>");
}
The slots are just time ranges available, different staff members offer different services so each service may be 35 mins or 45 mins
the idea is if a service will fit in to a time frame that is available and if so, fit the availabilty around so there is no overlap either side.
Its more the php analysis to insert a booking time range ie 9:00 - 9:45 and search for times before and after and alter their times
so they match up ie from 08:00 - 08:59 and 9:46 - 11:00
eg
Slot booked at 9:45 - 10:15
9:00 - 9:30 available
9:31 - 10:00 available
10:01 - 10:30 available
After booking, row 2 is deleted as booking fills this slot fully,
row 1 finish time is 1 minute before start of booking and row 3 start time is 1 minute after booking finish time
I was asking because I was getting ready to suggest a slight table change as long as it fits your requirements. I would probably run a table of “available time slots” and then a second table of bookings. The time slot is available if the count of an inner join between the two tables with the correct criteria is null.
EDIT: Also, I’d change your date/time format on the table.