I need help with my php script. I am working on a script that allows my users to choose a time for their class. The time list is locked on a 24 hour grid, meaning a class can only happen every hour.
The goal of this script is to show the user a simple form with the available times.
There are 24 possible times in a day for one room. *I have three rooms.*
I understand how to make the form later on, what I don’t get is how to show available times if there are three rooms.
Here is what I got so far:
<?php
include 'db-connect.php';
if (isset($_GET['month']) && isset($_GET['day']) && isset($_GET['year'])) {
$month = $_GET['month'];
$day = $_GET['day'];
$year = $_GET['year'];
//string together date
$date = $month."/".$day."/".$year;
//return classes on this date
$sql = mysql_query("SELECT start_time, server FROM classes WHERE date = '$date'");
if (mysql_num_rows($sql)<=0) {
echo "show all the times.";
}else {
$timelist = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);
$servers = array(1,2,3);
while($query = mysql_fetch_array($sql)) {
unset($timelist[$query['start_time'] - 1]);
}
}
}
?>
Database Example:
+---------------------------------------------------------------------------------------+
| classID | trainerID | type | date | start_time | duration | server | define |
+---------------------------------------------------------------------------------------+
| 1 | 1 | 12 | 08/7/2011 | 9 | 60 | 1 | dummy class |
+---------------------------------------------------------------------------------------+
Instead of your current strategy you could just store the number of arrays each time is found in, like:
Now $timelist is an array of times that were found in all three queries. If you want an array of times that were missing from at least one query use this instead of the last few lines: