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

// Check if student exists
$stmt = $pdo->prepare("SELECT id, student_id, first_name, last_name FROM students WHERE id = ?");
$stmt->execute([6192]);
$student = $stmt->fetch();

if (!$student) {
    echo "Student with ID 6192 not found\n";
    exit;
}

echo "Student Info:\n";
echo "ID: " . $student['id'] . "\n";
echo "Student ID: " . $student['student_id'] . "\n";
echo "Name: " . $student['first_name'] . " " . $student['last_name'] . "\n\n";

// Check student's subjects
$stmt = $pdo->prepare("
    SELECT ss.subject_id, ss.is_fourth_subject, sub.name 
    FROM student_subjects ss 
    JOIN subjects sub ON ss.subject_id = sub.id 
    WHERE ss.student_id = ?
");
$stmt->execute([6192]);
$subjects = $stmt->fetchAll();

echo "Student's Subjects:\n";
foreach ($subjects as $subject) {
    echo "Subject: " . $subject['name'] . " (ID: " . $subject['subject_id'] . ")";
    echo " - Fourth Subject: " . ($subject['is_fourth_subject'] ? 'Yes' : 'No') . "\n";
}

echo "\n";

// Check if student_subjects table has is_fourth_subject column
$stmt = $pdo->prepare("SHOW COLUMNS FROM student_subjects LIKE 'is_fourth_subject'");
$stmt->execute();
$column = $stmt->fetch();

if ($column) {
    echo "is_fourth_subject column exists in student_subjects table\n";
} else {
    echo "is_fourth_subject column does NOT exist in student_subjects table\n";
}

// Check results for this student
$stmt = $pdo->prepare("
    SELECT r.*, sub.name as subject_name
    FROM results r
    JOIN subjects sub ON r.subject_id = sub.id
    WHERE r.student_id = ? AND r.session = ? AND r.exam_type = ?
    ORDER BY sub.name
");
$stmt->execute([6192, 2025, 'test']);
$results = $stmt->fetchAll();

echo "\nStudent's Results:\n";
foreach ($results as $result) {
    echo "Subject: " . $result['subject_name'] . " - Marks: " . $result['marks_obtained'] . " - Grade: " . $result['grade'] . "\n";
}
?>