I'm using my school's api for the cs departments course schedule. It provides me a json file that I'm outputting on my webpage separated by each semester. Currently I'm able to have the output of all the courses in each semester sorted by the course ID. However, I'm trying to sort each semester by the day that the class is offered. Monday and Monday/Wednesday classes would be listed first, then Tuesday and Tuesday/Thursday and so on.
In my printListings function I'm able to print the entire course schedule out. And I'm able to add the line:
// if first character of days is an "M"
if(strcmp(substr($course->meetingTimes[0]->days, 0, 1), 'M')) continue;
which causes only monday and monday/wednesday courses to appear. However if I try adding a copy of the same line and just change the "M" to a "T" it causes my entire webpage to appear blank. Why is this?
printListing function:
function printListing($apiCall) {
$json = curl_get_contents($apiCall);
$obj = json_decode($json);
if (!($obj->courses == null)) {
echo "<table border='3' width='100%'>";
foreach ($obj->courses as $course) {
// if first character of days is an "M"
if(strcmp(substr($course->meetingTimes[0]->days, 0, 1), 'M')) continue;
//if(strcmp(substr($course->meetingTimes[0]->days, 0, 1), 'T')) continue;
//if(strcmp(substr($course->meetingTimes[0]->days, 0, 1), 'W')) continue;
//if(strcmp(substr($course->meetingTimes[0]->days, 0, 1), 'R')) continue;
$building = strtoupper(trim($_GET['building']));
$buildingMatch = false;
$thisBuilding0 = trim($course->meetingTimes[0]->building);
$thisBuilding1 = trim($course->meetingTimes[1]->building);
if ($building && ($thisBuilding0 == $building || $thisBuilding1 == $building))
$buildingMatch = true;
if (!($building))
$buildingMatch = true;
if (!$buildingMatch)
continue;
$room = strtoupper(trim($_GET['room']));
$roomMatch = false;
$thisroom0 = trim($course->meetingTimes[0]->room);
$thisroom1 = trim($course->meetingTimes[1]->room);
if ($room && ($thisroom0 == $room || $thisroom1 == $room))
$roomMatch = true;
if (!($room))
$roomMatch = true;
if (!$roomMatch)
continue;
// different <tr bgcolor=...> for each professor
switch ($course->meetingTimes[0]->instructor) {
case "proff1": // 1
$printline = "<tr bgcolor='#B19CD9'>"; // pastel purple
break;
case "proff2": // 2
$printline = "<tr bgcolor='lightblue'>"; // light blue
break;
case "proff3": // 3
$printline = "<tr bgcolor='pink'>"; // pink
break;
case "proff4": // 4
$printline = "<tr bgcolor='yellow'>"; // yellow
break;
case "proff5": // 5
$printline = "<tr bgcolor='#77DD77'>"; // pastel green (light green)
break;
case "proff6": // 6
$printline = "<tr bgcolor='#FFB347'>"; // pastel orange
break;
default:
$printline = "<tr>"; // no background color
}
$printline .= "<td width='13%'>" . $course->prefix . " " . $course->courseNumber . "*" . $course->section . "</td>";
$printline .= "<td width='40%'>" . $course->title . " (" . $course->lineNumber . ")" . "</td>";
$printline .= "<td width='12%'>Av:" . $course->seatsAvailable . " (" . $course->capacity . ")" . "</td>";
// print day and time column
if ($course->meetingTimes[0]->days) {
$printline .= "<td width='15%'>" . $course->meetingTimes[0]->days . " " . $course->meetingTimes[0]->startTime;
// $printline .= . "<br /> " . $course->meetingTimes[1]->days . " " . $course->meetingTimes[1]->startTime ;
$printline .= "</td>";
} else {
$printline .= "<td width='15%'>";
$printline .= $course->meetingTimes[1]->days . " " . $course->meetingTimes[1]->startTime . "</td> ";
}
// print building and room column
$printline .= "<td width='10%'>";
if (substr($course->section, -2, 1) == "9")
$printline .= "(Online)";
else
if (substr($course->section, -2, 1) == "7")
$printline .= $course->meetingTimes[1]->building . " " . $course->meetingTimes[1]->room;
else
$printline .= $course->meetingTimes[0]->building . " " . $course->meetingTimes[0]->room;
$printline .= "</td>";
// print instructor column
$printline .= "<td width='10%'>" . $course->meetingTimes[0]->instructor . "</td>";
$printline .= "</tr>";
echo $printline;
} // end foreach
echo "</table>";
echo "<br/>";
} // end if (!($obj->courses == null))
else {
echo "No courses fit search criteria";
echo "<br />";
}
}