// QUERY TO FIND THE RESOURCE FREE DURING THIS TIME
$sql = "SELECT id FROM calendar WHERE ( ('$my_start' NOT BETWEEN start AND end) OR ('$my_stopt' NOT BETWEEN start AND end) )";
// QUERY TO FIND A RESOURCE THAT IS FREE DURING THIS TIME
$sql = "SELECT id, name FROM calendar WHERE ( ('$my_start' NOT BETWEEN start AND end) AND ('$my_stopt' NOT BETWEEN start AND end) ) ";
// RUN THE QUERY AND TEST THE RESULTS
$res = mysql_query($sql);
if (!$res) die( mysql_error() );
// IF NOTHING WAS FOUND, EVERY POSSIBLE name IS ALREADY SCHEDULED
if (!$num = mysql_num_rows($res))
{
die('NOTHING AVAILABLE');
}
// SHOW HOW MANY name RESOURCES CAN BE FOUND
echo "<br/>$num RESOURCES ARE AVAILABLE \n";
// ITERATE OVER THE RESULTS SET
while ($row = mysql_fetch_assoc($res))
{
extract ($row);
echo "<br/>AVAILABLE: $id $name \n";
}
Name (in your case this might be the room number)
User (this might be the person reserving the resource)
Start DATETIME
End DATETIME
Simplistic as it sounds, that is ALL you need, and everything else is optional. The optional things might include descriptions, URLs, contact email addresses, etc.
There are a lot of things you can add to this problem (and as you add them you will quickly come to see why the calendar project is a college semester) such as permission levels. For example, if I schedule a room for a week, but my boss want to take the room away from me on Wednesday and Thursday, then he changes his mind and wants to give back Wednesday, but HIS boss says, "no"...
For query speed, you would usually add indexes to your tables, but in calendar processing you can't really do this - the DATETIME fields will almost certainly contain duplicate values. But having said that, let me reassure you that unless you are scheduling many thousands of rooms, you will never see a speed issue in a calendar application.
To allocate a resource to a user, you add an element to the calendar table with all four of those fields filled in.
To determine if a resource is available over a particular timeframe, you query the table for any rows that match the resource and have an expressed start or end that is within the timeframe (use BETWEEN in the MySQL query).
That's all there is to the framework. Please post back here if you have any questions.
best regards, ~Ray