Thanks for those pointers, big.nerd. They've been a great help in getting started, now I seem to stuck again. I've adopted the mySQL table structure you gave with a start_date and an end_date, and then I've already formed a mySQL query.
I'm also using the calendar script you gave me as it seems like it'll work; I just need to format the operating days into this structure:
$days = array(
2=>array('/weblog/archive/2004/Jan/02','linked-day'),
3=>array('/weblog/archive/2004/Jan/03','linked-day'),
8=>array('/weblog/archive/2004/Jan/08','linked-day'),
22=>array('/weblog/archive/2004/Jan/22','linked-day'),
);
But now for where I'm stuck. I have a for loop that loops through each day in the month and I already have the timestamp for each day. I have no clue how to manipulate the associated array I got from the mySQL query to get the open_time and close_time for a given timestamp. This seems especially bewildering to me when the timestamp is part of a range. How can I take the mySQL query results and get the open and close times given a timestamp? My code is below...
// First, let's determine the first and last days for the month given...
// This will help us define the SQL query to get the operating hours for the desired month
// Was a month set?
if(is_numeric($_GET['m'])){
// If the year was set, use that year... Otherwise, use this year
if(isset($_GET['y']) and is_numeric($_GET['y'])){
$year = $_GET['y'];
}
else {
$year = date('Y');
}
$first_day = mktime(0,0,0,$_GET['m'],1,$year);
$last_day = mktime(0,0,0,$_GET['m']+1,0,$year);
$num_of_days = date('t',$first_day); // # of days in the month
}
else{
// No month given... Default to this month and get the first/last day
$first_day = mktime(0,0,0,date('n'),1,date('Y'));
$last_day = mktime(0,0,0,date('n'),date('t'),date('Y'));
$num_of_days = date('t',$first_day);
}
// Generate the query
$query = "SELECT * FROM parkhours WHERE start_date >= $first_day AND end_date <= $last_day";
$hour_results = mysql_fetch_assoc(mysql_query($query));
// Loop through each day of the month, assigning the hours to an array that can be used in
// the following calendar script
for($day = 0; $day < $num_of_days; $day++){
// Make the timestamp for each date, using the first day's timestamp and adding to it the
// number of days times the seconds in a day
$current_timestamp = $first_day + $day*86400;
// Get the open_time and close_time for that timestamp from the mySQL query
// ?????????????????????
}
Thanks again for all the help you've provided so far! Seems like after this hurdle I'll be set! 🙂