query($sql);
// Check if the query was successful
if (!$result) {
die("Query failed: " . $conn->error);
}
// School Information
$school_name = "Your School Name";
$po_box = "P.O. Box 1234, Your City";
$phone_numbers = "(123) 456-7890";
function calculateGrade(array $marks): string {
$failCount = 0;
$totalMarks = 0;
$validMarksCount = 0;
foreach ($marks as $mark) {
if ($mark >= 0) { // Only consider non-negative marks
if ($mark < 50) {
$failCount++;
}
$totalMarks += $mark;
$validMarksCount++;
}
}
// Return 'X' if there are no valid marks
$average = $totalMarks / $validMarksCount; // Calculate average
// Determine grade based on the average
if ($average >= 80) return 'A'; // Excellent
if ($average >= 75) return 'B'; // Very Good
if ($average >= 60) return 'C'; // Good
if ($average >= 50) return 'D'; // Fair
if ($average >= 45) return 'E';
if ($average >= 40) return 'O';
if ($average >= 39) return 'F';
if ($average = "" || $average >= 0) return 'X';
return 'F'; // Default fail if none of the above conditions are met
}
function getValidSubjects($student, $subjects) {
$validSubjects = [];
foreach ($subjects as $subject) {
$marks = [];
foreach ($subject['marks'] as $mark) {
$marks[] = isset($student[$mark]) ? $student[$mark] : -1; // Use -1 for invalid marks
}
// Only add to valid subjects if not all marks are negative
if (array_sum($marks) >= 0) {
$validSubjects[] = $subject;
}
}
return $validSubjects;
}
?>
Student Report Cards
Student Report Cards
num_rows > 0): ?>
fetch_assoc()): ?>
Phone:
Student Name:
Subjects
Criteria
Grade
P1
P2
P3
P4
P5
P6
P7
'GP', 'criteria' => 'subsidiary', 'marks' => ['gp']],
['name' => 'Computer Studies', 'criteria' => 'subsidiary pass', 'marks' => ['ict1', 'ict2']],
['name' => 'Sub Mathematics', 'criteria' => 'subsidiary pass', 'marks' => ['submath']],
['name' => 'Mathematics', 'criteria' => 'principal pass', 'marks' => ['mtc1', 'mtc2']],
['name' => 'Physics', 'criteria' => 'principal pass', 'marks' => ['phy1', 'phy2', 'phy3']],
['name' => 'Biology', 'criteria' => 'principal pass', 'marks' => ['bio1', 'bio2', 'bio3']],
['name' => 'Chemistry', 'criteria' => 'principal pass', 'marks' => ['chem1', 'chem2', 'chem3']],
['name' => 'Geography', 'criteria' => 'principal pass', 'marks' => ['geo1', 'geo2', 'geo3']],
['name' => 'History', 'criteria' => 'principal pass', 'marks' => ['hist1', 'hist']],
['name' => 'Divinity', 'criteria' => 'principal pass', 'marks' => ['cre', 'div2', 'div3']],
['name' => 'Luganda', 'criteria' => 'principal pass', 'marks' => ['lug1', 'lug2', 'lug3']],
['name' => 'Entrepreneurship', 'criteria' => 'principal pass', 'marks' => ['ent', 'ent2', 'ent3']],
['name' => 'Kiswahili', 'criteria' => 'principal pass', 'marks' => ['kisw1', 'kisw2', 'kisw3']],
['name' => 'Fine Art', 'criteria' => 'principal pass', 'marks' => ['art1', 'art2', 'art3', 'art4']],
['name' => 'Technical Drawing', 'criteria' => 'principal pass', 'marks' => ['td1', 'td2', 'td3']],
['name' => 'Literature', 'criteria' => 'principal pass', 'marks' => ['lit1', 'lit2', 'lit3']],
['name' => 'Economics', 'criteria' => 'principal pass', 'marks' => ['econ1', 'econ2', 'econ3']],
];
// Iterate through subjects for the current student
foreach ($subjects as $subject) {
$marks = [];
$hasMissingMarks = false; // Flag for missing marks
foreach ($subject['marks'] as $mark) {
if (isset($student[$mark]) && $student[$mark] !== '') {
$marks[] = $student[$mark]; // Collect valid marks
} else {
$marks[] = 'X'; // Mark as missed paper
$hasMissingMarks = true; // Set flag for missing marks
}
}
// Determine grade based on the presence of missing marks
$grade = '';
if ($subject['criteria'] === 'principal pass') {
if ($hasMissingMarks) {
$grade = 'X'; // Set grade to 'X' if any marks are missing
} else {
$grade = calculateGrade($marks);
}
} elseif ($subject['criteria'] === 'subsidiary pass') {
if ($hasMissingMarks) {
$grade = 'X'; // Set grade to 'X' if any marks are missing
} else {
// Calculate the average for subsidiary subjects
$average = array_sum($marks) / count($marks);
$grade = ($average >= 50) ? '1' : ''; // Assign "1" if average is 50 or above
}
}
echo "
";
echo "
" . htmlspecialchars($subject['name']) . "
";
echo "
" . htmlspecialchars($subject['criteria']) . "
";
echo "
" . htmlspecialchars($grade) . "
"; // Display the grade
// Output the marks for each paper
foreach ($subject['marks'] as $mark) {
echo "