Let's try a little logic excercise here:
<?php
$arTimeSegments = array(
"0000:2400" => "All Time Segments",
"0700:0800" => "7am to 8am",
"0730:0830" => "7:30am to 8:30am",
"0800:0900" => "8am to 9am",
"0900:1000" => "9am to 10am",
"1000:1100" => "10am to 11am",
"1100:1200" => "11am to 12pm",
"1200:1300" => "12pm to 1pm"
);
$arClasses = array(
"Biology" => array(
"teacher" => "Samuel L.",
"time" => "0845:1000"
),
"Chemistry" => array(
"teacher" => "Glora E.",
"time" => "0800:0900"
),
"Physics" => array(
"teacher" => "Albert E.",
"time" => "1000:1200"
),
"Bowling" => array(
"teacher" => "Jean W.",
"time" => "1500:1400"
),
);
?>
<html>
<body>
<form action="?" method="GET">
Time Segment:
<select name="timesegment" onchange="submit()">
<?php
@reset($arTimeSegments);
while (list($strTime, $strTimeInEnglish) = @each($arTimeSegments))
{
echo "<option value=\"{$strTime}\"".
($_GET["timesegment"]==$strTime ? " selected=\"selected\"":"").
">{$strTimeInEnglish}</option>\n";
}
?>
</select>
<hr>
<?php
if (!empty($_GET["timesegment"]))
{
$strTimeSegmentValue = $_GET["timesegment"];
list($timesegmentstart, $timesegmentend) = split(":", $strTimeSegmentValue);
echo "Listing classes for {$arTimeSegments[$strTimeSegmentValue]}<br />\n";
?>
Lecture:
<select name="lecture" onchange="submit()">
<option value="">...</option>
<?php
@reset($arClasses);
while (list($strLecture, $arLectureProperty) = @each($arClasses))
{
$thisTimeSegment = $arLectureProperty["time"];
list($startTime, $endTime) = split(":", $thisTimeSegment);
if ((($startTime < $timesegmentstart) ||
($startTime > $timesegmentend)) &&
(($endTime < $timesegmentstart) ||
($endTime > $timesegmentend)))
{
// this class does not fit in this time frame
continue;
}
else
{
echo "<option value=\"{$strLecture}\"".
($_GET["lecture"]==$strLecture ? " selected=\"selected\"":"").
">{$strLecture}</option>\n";
}
}
?>
</select>
<hr />
<?php
if (!empty($_GET["lecture"]))
{
echo "Supervisor/Teacher for <b>{$_GET['lecture']}</b>: <b>{$arClasses[$_GET['lecture']]['teacher']}</b>";
}
}
?>
</form>
</body>
</html>
I'm using associative arrays to mimic database records/fields - I admit it looks a little daunting and long-winded but it gets the job done.