query($sql); // Check if the query was successful if (!$result) { die("Query failed: " . $conn->error); } // School Information define('SCHOOL_NAME', 'HANDS OF LOVE - KABAGA'); define('PO_BOX', 'P.O. Box 1234, KAMPALA'); define('PHONE_NUMBERS', '(256) 456-7890'); function getGrade($score) { if (!is_numeric($score) || $score < 0 || $score > 100) { return "Invalid score"; } // Define grade thresholds $grades = [ 'D1' => [85, 100], 'D2' => [80, 84], 'C3' => [75, 79], 'C4' => [66, 74], 'C5' => [56, 65], 'C6' => [50, 55], 'P7' => [45, 49], 'P8' => [40, 44], 'F9' => [0, 39], ]; // Determine the grade based on the score foreach ($grades as $grade => $range) { if ($score >= $range[0] && $score <= $range[1]) { return $grade; } } return "F"; // Default case, should not reach here } function determineGrade($paper1, $paper2) { // Check for X grade when either paper has a score of 0 if ($paper1 === "0" || $paper2 === "0") { return ""; } // Check grades and return appropriate letter if (($paper1 === "D1" && $paper2 === "D1") || ($paper1 === "D1" && $paper2 === "D2") || ($paper1 === "D2" && $paper2 === "D1") || ($paper1 === "D2" && $paper2 === "D2")) { return "A"; } elseif (($paper1 === "D1" && $paper2 === "C3") || ($paper1 === "D2" && $paper2 === "C3") || ($paper1 === "C3" && $paper2 === "C3")) { return "B"; } elseif (($paper1 === "D1" && $paper2 === "C4") || ($paper1 === "D2" && $paper2 === "C4") || ($paper1 === "C3" && $paper2 === "C4") || ($paper1 === "C5" && $paper2 === "C5")) { return "C"; } elseif (($paper1 === "D1" && $paper2 === "C5") || ($paper1 === "D2" && $paper2 === "C5") || ($paper1 === "C3" && $paper2 === "C5") || ($paper1 === "C4" && $paper2 === "C5")) { return "D"; } elseif (($paper1 === "D1" && $paper2 === "C6") || ($paper1 === "D2" && $paper2 === "C6") || ($paper1 === "C3" && $paper2 === "C6") || ($paper1 === "C4" && $paper2 === "C6") || ($paper1 === "C5" && $paper2 === "C6") || ($paper1 === "C6" && $paper2 === "C6") || ($paper1 === "D1" && $paper2 === "P7") || ($paper1 === "D2" && $paper2 === "P7") || ($paper1 === "C3" && $paper2 === "P7") || ($paper1 === "C4" && $paper2 === "P7") || ($paper1 === "C5" && $paper2 === "P7") || ($paper1 === "D1" && $paper2 === "P8") || ($paper1 === "D2" && $paper2 === "P8") || ($paper1 === "C3" && $paper2 === "P8") || ($paper1 === "C4" && $paper2 === "P8")) { return "E"; } elseif (($paper1 === "C6" && $paper2 === "P7") || ($paper1 === "P7" && $paper2 === "P7") || ($paper1 === "P7" && $paper2 === "P8") || ($paper1 === "C5" && $paper2 === "P8") || ($paper1 === "C6" && $paper2 === "P8") || ($paper1 === "P8" && $paper2 === "P8") || ($paper1 === "D1" && $paper2 === "F9") || ($paper1 === "C6" && $paper2 === "F9")) { return "O"; } elseif (($paper1 === "P8" && $paper2 === "F9") || ($paper1 === "F9" && $paper2 === "F9")) { return "F"; } } function determineGradeThreePapers($paper1, $paper2, $paper3) { // Check for empty score when any paper has a score of 0 if ($paper1 === "0" || $paper2 === "0" || $paper3 === "0") { return ""; // Return empty string instead of "X" } // Grading logic if (($paper1 === "D1" && $paper2 === "D1" && $paper3 === "C3") || ($paper1 === "D1" && $paper2 === "D2" && $paper3 === "C3") || ($paper1 === "D2" && $paper2 === "D2" && $paper3 === "C3")) { return "A"; } elseif (($paper1 === "D1" && $paper2 === "D1" && $paper3 === "C4") || ($paper1 === "C3" && $paper2 === "C3" && $paper3 === "C4") ) { return "B"; } elseif (($paper1 === "D1" && $paper2 === "D1" && $paper3 === "C5") || ($paper1 === "C4" && $paper2 === "C4" && $paper3 === "C5")) { return "C"; } elseif (($paper1 === "D1" && $paper2 === "D1" && $paper3 === "C6") || ($paper1 === "C5" && $paper2 === "C5" && $paper3 === "C6")) { return "D"; } elseif (($paper1 === "D1" && $paper2 === "D1" && $paper3 === "P7") || ($paper1 === "C6" && $paper2 === "C6" && $paper3 === "P7") || ($paper1 === "P8" && $paper2 === "C6" && $paper3 === "C5")) { return "E"; } elseif (($paper1 === "F9" && $paper2 === "F9" && $paper3 === "F9") || ($paper1 === "F9" && $paper2 === "F9" && $paper3 === "P7") || ($paper1 === "D1" && $paper2 === "D1" && $paper3 === "F9") || ($paper1 === "P8" && $paper2 === "P8" && $paper3 === "F9") || ($paper1 === "P8" && $paper2 === "P8" && $paper3 === "P8") || ($paper1 === "P7" && $paper2 === "P7" && $paper3 === "P7")) { return "O"; } elseif (($paper1 === "F9" && $paper2 === "F9" && $paper3 === "P8") || ($paper1 === "F9" && $paper2 === "F9" && $paper3 === "F9")) { return "F"; } return "F"; // Default case if no other conditions are met } ?> Student Report Cards

Student Report Cards

num_rows > 0): ?> fetch_assoc()): ?>

Phone:

Student Name:

'GP', 'criteria' => 'subsidiary', 'marks' => [$student['gp'], null, null, null, null, null, null]], ['name' => 'Computer Studies', 'criteria' => 'subsidiary pass', 'marks' => [$student['ict1'], $student['ict2'], null, null, null, null, null]], ['name' => 'Sub Mathematics', 'criteria' => 'subsidiary pass', 'marks' => [$student['submath'], null, null, null, null, null, null]], ['name' => 'Mathematics', 'criteria' => 'principal pass', 'marks' => [$student['mtc1'], $student['mtc2'], null, null, null, null, null]], ['name' => 'Physics', 'criteria' => 'principal pass', 'marks' => [$student['phy1'], $student['phys2'], null, null, null, null, null]], ['name' => 'Biology', 'criteria' => 'principal pass', 'marks' => [$student['bio1'], $student['bio2'], null, null, null, null, null]], ['name' => 'Chemistry', 'criteria' => 'principal pass', 'marks' => [$student['chem1'], $student['chem2'], $student['chem3'], null, null, null, null]], ['name' => 'Geography', 'criteria' => 'principal pass', 'marks' => [$student['geo1'], $student['geo2'], $student['geo3'], null, null, null, null]], ['name' => 'History', 'criteria' => 'principal pass', 'marks' => [$student['hist1'], $student['hist2'], null, null, null, null, null]], ['name' => 'Divinity', 'criteria' => 'principal pass', 'marks' => [$student['cre'], $student['div2'], $student['div3'], null, null, null, null]], ['name' => 'Luganda', 'criteria' => 'principal pass', 'marks' => [$student['lug1'], $student['lug2'], $student['lug3'], null, null, null, null]], ['name' => 'Entrepreneurship', 'criteria' => 'principal pass', 'marks' => [$student['ent'], $student['ent2'], $student['ent3'], null, null, null, null]], ['name' => 'Kiswahili', 'criteria' => 'principal pass', 'marks' => [$student['kisw1'], $student['kisw2'], $student['kisw3'], null, null, null, null]], ['name' => 'Fine Art', 'criteria' => 'principal pass', 'marks' => [$student['art1'], $student['art2'], $student['art3'], $student['art4'], null, null, null]], ['name' => 'Technical Drawing', 'criteria' => 'principal pass', 'marks' => [$student['td'], $student['td2'], $student['td3'], null, null, null, null]], ['name' => 'Literature', 'criteria' => 'principal pass', 'marks' => [$student['lit1'], $student['lit2'], $student['lit3'], null, null, null, null]], ['name' => 'Economics', 'criteria' => 'principal pass', 'marks' => [$student['econ1'], $student['econ2'],null, null, null, null, null]], ]; // Iterate through subjects to calculate grades foreach ($subjects as $subject) { $grades = array_map('getGrade', array_filter($subject['marks'])); // Final grade calculation if (in_array("0", $subject['marks'])) { $final_grade = ""; } else { $final_grade = count($grades) > 1 ? determineGrade($grades[0], $grades[1]) : ($grades[0] ?? "F"); } // Display subject information in the table echo ""; } ?>
Subject Criteria P1 P2 P3 P4 P5 P6 P7 Grade
{$subject['name']} {$subject['criteria']} " . ($subject['marks'][0] !== null && $subject['marks'][0] !== "0" ? $subject['marks'][0] : '') . " " . ($subject['marks'][1] !== null && $subject['marks'][1] !== "0" ? $subject['marks'][1] : '') . " " . ($subject['marks'][2] !== null && $subject['marks'][2] !== "0" ? $subject['marks'][2] : '') . " " . ($subject['marks'][3] !== null && $subject['marks'][3] !== "0" ? $subject['marks'][3] : '') . " " . ($subject['marks'][4] !== null && $subject['marks'][4] !== "0" ? $subject['marks'][4] : '') . " " . ($subject['marks'][5] !== null && $subject['marks'][5] !== "0" ? $subject['marks'][5] : '') . " " . ($subject['marks'][6] !== null && $subject['marks'][6] !== "0" ? $subject['marks'][6] : '') . " {$final_grade}
No student records found.