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

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

    // Check if student exists
    $stmt = $pdo->prepare('SELECT * FROM students WHERE id = ?');
    $stmt->execute([$student_id]);
    $student = $stmt->fetch();
    echo 'Student: ' . ($student ? $student['first_name'] . ' ' . $student['last_name'] : 'Not found') . PHP_EOL;

    // Check student subjects
    $stmt = $pdo->prepare('SELECT ss.*, s.name as subject_name FROM student_subjects ss JOIN subjects s ON ss.subject_id = s.id WHERE ss.student_id = ?');
    $stmt->execute([$student_id]);
    $subjects = $stmt->fetchAll();
    echo 'Student subjects count: ' . count($subjects) . PHP_EOL;
    foreach ($subjects as $subject) {
        echo '  - ' . $subject['subject_name'] . ' (4th: ' . $subject['is_fourth_subject'] . ')' . PHP_EOL;
    }

    // Check results for this student
    $stmt = $pdo->prepare('SELECT COUNT(*) as result_count FROM results WHERE student_id = ? AND session = ? AND exam_type = ?');
    $stmt->execute([$student_id, $session, $exam_type]);
    $result_count = $stmt->fetch()['result_count'];
    echo 'Results count for 2025 final: ' . $result_count . PHP_EOL;

} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
?>