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

// Test student enrolled subjects
$stmt = $pdo->prepare('SELECT s.name as subject_name FROM student_subjects ss JOIN subjects s ON ss.subject_id = s.id WHERE ss.student_id = ?');
$stmt->execute([6192]);
$subjects = $stmt->fetchAll();
echo "Student 6192 enrolled subjects: ";
foreach ($subjects as $subject) {
    echo $subject['subject_name'] . ' ';
}
echo PHP_EOL;

// Test exam subjects
$stmt = $pdo->prepare('SELECT es.*, s.name as subject_name, s.code as subject_code FROM exam_subjects es JOIN subjects s ON es.subject_id = s.id WHERE es.exam_id = ? ORDER BY es.exam_date, es.start_time');
$stmt->execute([68]);
$subjects = $stmt->fetchAll();
echo "Exam 68 subjects: ";
foreach ($subjects as $subject) {
    echo $subject['subject_name'] . '(' . $subject['subject_code'] . ') ';
}
echo PHP_EOL;

// Test modified query - exam subjects that student is enrolled in
$stmt = $pdo->prepare("
    SELECT es.*, s.name as subject_name, s.code as subject_code
    FROM exam_subjects es
    JOIN subjects s ON es.subject_id = s.id
    JOIN student_subjects ss ON es.subject_id = ss.subject_id
    WHERE es.exam_id = ? AND ss.student_id = ?
    ORDER BY es.exam_date, es.start_time
");
$stmt->execute([68, 6192]);
$subjects = $stmt->fetchAll();
echo "Exam 68 subjects that student 6192 is enrolled in: ";
foreach ($subjects as $subject) {
    echo $subject['subject_name'] . '(' . $subject['subject_code'] . ') ';
}
echo PHP_EOL;
?>