<?php
require_once 'config/database.php';

$student_id = 6279;
$session = 2025;
$exam_type = 'final';

$stmt = $pdo->prepare('SELECT r.*, s.name as subject_name, s.code, ss.is_fourth_subject FROM results r JOIN subjects s ON r.subject_id = s.id JOIN student_subjects ss ON r.student_id = ss.student_id AND r.subject_id = ss.subject_id WHERE r.student_id = ? AND r.session = ? AND r.exam_type = ? ORDER BY s.name');
$stmt->execute([$student_id, $session, $exam_type]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo "Raw results from database:\n";
foreach($results as $r) {
    echo $r['subject_name'] . ': ' . $r['marks_obtained'] . '/' . $r['full_marks'] . ' = ' . $r['grade'] . ' (4th: ' . ($r['is_fourth_subject'] ? 'Yes' : 'No') . ")\n";
}
?>
