$result = $mysqli->prepare("SELECT DISTINCT idfeedback_release, type FROM properties, properties_modules, feedback_release WHERE feedback_release.paper_id = properties.property_id AND properties.property_id = properties_modules.property_id {$date_range} AND paper_type = '2' AND idMod IN (" . implode(',', $moduleIDs) . ") AND deleted IS NULL");
        $result->execute();
        $result->bind_result($idfeedback_release, $type);
        while ($result->fetch()) {
            $master_array[$school][$type]++;
        }
        $result->close();
    }
}
$parts = array('exams', 'objectives', 'questions', 'cohort_performance', 'external_examiner');
$old_faculty = '';
$faculty_stats = array(0, 0, 0, 0, 0);
foreach ($master_array as $school => $data) {
    if ($old_faculty != $data['faculty']) {
        if ($old_faculty != '') {
            echo output_faculty_stats($faculty_stats);
        }
        echo '<tr><td colspan="6" class="faculty">' . $data['faculty'] . '</td></tr>';
        $faculty_stats = array(0, 0, 0, 0, 0);
    }
    echo "<tr><td>" . $school . "</td>";
    for ($i = 0; $i < 5; $i++) {
        $part = $parts[$i];
        if ($data[$part] == 0) {
            echo "<td class=\"n grey\">" . $data[$part] . "</td>";
        } else {
            if ($i == 1 or $i == 2 or $i == 3) {
                echo "<td class=\"n\"><a href=\"feedback_detail.php?calyear=" . $_GET['calyear'] . "&school=" . $master_array[$school]['id'] . "&type={$i}\">" . $data[$part] . "</a></td>";
            } else {
                echo "<td class=\"n\">" . $data[$part] . "</td>";
            }
        $date_range = '';
        $result = $mysqli->prepare("SELECT DISTINCT questions.q_id, q_type FROM questions, questions_modules WHERE questions.q_id = questions_modules.q_id AND idMod IN (" . implode(',', $moduleIDs) . ") AND deleted IS NULL GROUP BY questions.q_id");
        $result->execute();
        $result->bind_result($q_id, $q_type);
        while ($result->fetch()) {
            $master_array[$school]['types'][$q_type]++;
        }
        $result->close();
    }
}
$old_faculty = '';
$faculty_stats = $types;
foreach ($master_array as $school => $data) {
    if ($old_faculty != $data['faculty']) {
        if ($old_faculty != '') {
            echo output_faculty_stats($faculty_stats, $types);
        }
        echo '<tr><td colspan="19" class="faculty">' . $data['faculty'] . '</td></tr>';
        $faculty_stats = array();
    }
    echo "<tr><td>" . $school . "</td>";
    foreach ($types as $type) {
        if ($data['types'][$type] == 0) {
            echo "<td class=\"n grey\">" . $data['types'][$type] . "</td>";
        } else {
            echo "<td class=\"n\">" . number_format($data['types'][$type]) . "</td>";
        }
        if (isset($faculty_stats[$type])) {
            $faculty_stats[$type] += $data['types'][$type];
        } else {
            $faculty_stats[$type] = $data['types'][$type];