imfromio Posted February 11, 2010 Share Posted February 11, 2010 Hello, I have some code for restaurant reservations that will check to see (among other things) if the restaurant is open that day. I have a schedule of open days: //Restuarant Open Times $available_main_array = array( 'Summer' => array( 'start' => 'May 1', 'end' => 'October 31', 'schedule' => array( 'Sunday' => array( array('17:00','24:00')), 'Monday' => array( array('17:00','24:00')), 'Tuesday' => array( array('17:00','24:00')), 'Wednesday' => array( array('17:00','24:00')), 'Thursday' => array( array('17:00','24:00')), 'Friday' => array( array('17:00','24:00')), 'Saturday' => array( array('17:00','24:00')))), 'Winter' => array( 'start' => 'November 1', 'end' => 'April 30', 'schedule' => array( 'Sunday' => array( array('17:00','24:00')), 'Friday' => array( array('17:00','24:00')), 'Saturday' => array( array('17:00','24:00'))))); And these checks: //Check Database Functions function available($array) { //return array('false',gmdate('g:i a',$array['etime'])); $week_schedule = availableArray($array['date']); $schedule = $week_schedule[date('l',$array['date'])]; if(is_array($schedule)) { foreach($schedule as $timespan) { if(gmdate('H:i',$array['stime'])<$timespan[0]) { return array('false','Sorry, we are not available at your starting time.'); } if(gmdate('H:i',$array['etime']-1)<$timespan[0]) { return array('false','Sorry, you cannot place an online reservation this late at night. Please call 920-854-9070 to place this reservation.'); } } return array('yay'); } else { return array('false','Sorry, we are not available on that day.'); } } function availableArray($date) { global $available_main_array; foreach($available_main_array as $season_array) { $start = $season_array['start']; $end = $season_array['end']; if(strtotime($end)<strtotime($start)) { $end .= ', '.(date('Y')+1); } else { $end .= ', '.date('Y'); } $start .= ', '.date('Y'); if($date>=strtotime($start)&&$date<=strtotime($end)) { return $season_array['schedule']; } } } The problem is, any dates entered from today (in the winter season) until May 1 (the start of the summer season) return the error 'Sorry, we are not available on that day.' So I think the problem is is how I'm advancing the year (in the avaiableArray function) when the winter season goes from say 12/31/09 to 1/1/10. But for the life of me, I can't find the error in the code. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/191798-check-schedule/ Share on other sites More sharing options...
ignace Posted February 11, 2010 Share Posted February 11, 2010 create table opening_hours ( id integer not null auto_increment, valid_from date, valid_until date, monday varchar(32), tuesday varchar(32), wednesday varchar(32), thursday varchar(32), friday varchar(32), primary key (id)); $query = 'SELECT monday, tuesday, wednesday, thursday, friday FROM opening_hours WHERE now() BETWEEN valid_from AND valid_until'; $result = mysql_query($query); list($monday, $tuesday, $wednesday, $thursday, $friday) = myql_fetch_array($result, MYSQL_NUM)) { //echo '<td>', $monday, '</td><td>', $tuesday, '</td><td>', $wednesday, '</td><td>', // $thursday, '</td><td>', $friday, '</td><td>'; The fields monday till friday would hold the opening hours like 17:00-24:00 Quote Link to comment https://forums.phpfreaks.com/topic/191798-check-schedule/#findComment-1010895 Share on other sites More sharing options...
imfromio Posted February 11, 2010 Author Share Posted February 11, 2010 Thanks...but I don't need to create a database table. I'm using the available_main_array to check availability. My problem is the winter season spans two years (i.e. 11/1/09-4/30/10). The code to check that is (I think) where I'm going wrong: function availableArray($date) { global $available_main_array; foreach($available_main_array as $season_array) { $start = $season_array['start']; $end = $season_array['end']; if(strtotime($end)<strtotime($start)) { $end .= ', '.(date('Y')+1); } else { $end .= ', '.date('Y'); } $start .= ', '.date('Y'); if($date>=strtotime($start)&&$date<=strtotime($end)) { return $season_array['schedule']; } Now that it's 2010, this code is saying the available dates during the winter season are 11/1/10-4/30/11. So people trying to book dates on say 2/14/10 get an error... Quote Link to comment https://forums.phpfreaks.com/topic/191798-check-schedule/#findComment-1010933 Share on other sites More sharing options...
ignace Posted February 12, 2010 Share Posted February 12, 2010 Well if you don't store it in a database then why don't you just create 2 files: summer.inc.php and winter.inc.php $time = time(); if ($time >= mktime(0, 0, 0, 5, 1) && $time <= mktime(0, 0, 0, 31, 10)) { include('summer.inc.php'); } else { include('winter.inc.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/191798-check-schedule/#findComment-1011373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.