// Check for a result
            if ($result == false) {
                // Something happened when talking to database, re-direct to logged-in home page
                // TODO: Implement proper error logging
                redirect('../../home.php');
            } else {
                if (mysqli_num_rows($result) > 0) {
                    // Iterate over the result set
                    $output = "";
                    while ($row = mysqli_fetch_assoc($result)) {
                        $output .= "\t\t<h2>";
                        //$output .= "<a href=\"./course/?cid=" . urlencode($row['id']) . "\">" . $row['code'] . ": " . $row['name'] . "</a>";
                        $output .= $row['code'] . ". " . $row['title'];
                        $output .= "</h2>\n";
                        // Now get the overall expectations for this strand id
                        $output .= get_overall_expectations($connection, $row['id'], $row['code']);
                    }
                } else {
                    $output = "No curriculum expectations defined for this course.";
                }
            }
        }
    }
}
?>

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
function get_expectations($db_connection, $cid)
{
    // Run query to get curriculum details for this course
    $query = "SELECT id, code, title FROM strand WHERE course_id = " . $cid . ";";
    $result = mysqli_query($db_connection, $query);
    // Check for a result
    if ($result == false) {
        // Something happened when talking to database, re-direct to logged-in home page
        // TODO: Implement proper error logging
        redirect('../../../home.php');
    } else {
        if (mysqli_num_rows($result) > 0) {
            // Iterate over the result set
            $output = "";
            while ($row = mysqli_fetch_assoc($result)) {
                $output .= "\t\t<h2>";
                $output .= $row['code'] . ". " . $row['title'];
                $output .= "</h2>\n";
                // Now get the overall expectations for this strand id
                $output .= get_overall_expectations($db_connection, $row['id'], $row['code']);
            }
        } else {
            $output = "No curriculum expectations defined for this course.";
        }
    }
    // Return the generated HTML
    return $output;
}
     // Something happened when talking to database, re-direct to logged-in home page
     // TODO: Implement proper error logging
     redirect('../../../home.php');
 } else {
     if (mysqli_num_rows($result) != 1) {
         // This shouldn't happen either, course-id should exist and return a single row, so,
         // re-direct to logged-in home page
         // TODO: Implement proper error logging
         redirect('../../../home.php');
     } else {
         // We have a valid result for this course
         $row = mysqli_fetch_assoc($result);
         $course_code = $row['code'];
         $course_id = $row['id'];
         // Generate the strands (needs to poll the database)
         $overall_expectations_dropdown_output = get_overall_expectations($connection, $course_id);
     }
 }
 // If there were no errors on basic validation of input, proceed
 if (!isset($message)) {
     // We have a valid result for this course
     $query = "INSERT INTO minor_expectation (overall_expectation_id, code, description)\n                                           VALUES (" . $provided_overall_expectation_id . ", '" . $provided_code . "', '" . $provided_description . "');";
     // Check to see if query succeeded
     if (!mysqli_query($connection, $query)) {
         // Show an error message, something unexpected happened (query should succeed)
         $message['general'] = "We could not create the minor expectation at this time. Please try again later.";
     } else {
         // All is well, re-direct to the logged-in curriculum page for this course
         redirect('../index.php?cid=' . $course_id);
     }
 }