Solarpitch Posted August 11, 2008 Share Posted August 11, 2008 Hi, I have a function that will return a day of the week, a start time and a finish time from the database. In the timetable, every time with an interval of 10 min from the start to finish time will not be available for reservations, but I'm not sure how to get it to work. <?php /*When user makes a reservation, this function will be called to return a day, start and finish time from the database. The day will be either in the format "Saturday"..."Sunday" etc and the time "7:00"..."8:00" etc. If the startTime is 7:00 and finishTime is 8:00 and the user tries to make a $reservationTime for 7:30 then I need to check this and return a message.*/ $reservationTime = "7:30"; $result = blocked(); foreach($result as $blocked) { $day = $blocked[0]; //returns Saturday $startTime= $blocked[1]; // returns "7:00" $finishTime = $blocked[2]; // returns "8:00" } //So what probably needs to be done is to calculate 10 min intervals from start to finish time and hold them in an array. Then we could say if $reservationTime in_array set an error. <? Gerard Link to comment https://forums.phpfreaks.com/topic/119114-using-an-array-in-a-timetable/ Share on other sites More sharing options...
Solarpitch Posted August 11, 2008 Author Share Posted August 11, 2008 Bump* Maybe the above question was a little hard to understand. I've been working further on it and have a bit more done. I think I'm almost there... <?php $result = blocked(); foreach($result as $blocked) { $day = $blocked[0]; //format "Saturday" $st = $blocked[3]; //format "7:00" $et = $blocked[4]; //format "8:00" } $st = strtotime(date('Y-m-d') . $st); $en = strtotime(date('Y-m-d') . $en); $int = 10 * 60; //Get the 10 min intervals between both start and finish time for ($i = $st; $i <= $en; $i += $int) { $hour = date('h:i a',$i); } ?> So I can calculate the intervals but I think I need to set up $st and $en as an array to store all the start times and end times that are being pulled from the blocked function on order to get this to work? Link to comment https://forums.phpfreaks.com/topic/119114-using-an-array-in-a-timetable/#findComment-613371 Share on other sites More sharing options...
JasonLewis Posted August 11, 2008 Share Posted August 11, 2008 To make it into an array, do the following: $ result = blocked(); foreach($result as $blocked) { $day = $blocked[0]; //format "Saturday" $st[] = $blocked[3]; //format "7:00" $et[] = $blocked[4]; //format "8:00" } You will then need to modify the rest of your code accordingly. Link to comment https://forums.phpfreaks.com/topic/119114-using-an-array-in-a-timetable/#findComment-613390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.