<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/includes/db.php';

try {
    $db = DB();
    $student = $db->fetchOne("SELECT * FROM students WHERE roll_number = '0026730012'");
    if ($student) {
        $studentId = $student['id'];
        echo "<h3>Student Basic Info:</h3><pre>";
        print_r($student);
        echo "</pre>";
        
        echo "<h3>Student Results Table Records:</h3><pre>";
        print_r($db->fetchAll("SELECT * FROM student_results WHERE student_id = ?", [$studentId]));
        echo "</pre>";
        
        echo "<h3>Subjects & Marks Entry Fallback Records:</h3><pre>";
        print_r($db->fetchAll("SELECT s.*, m.obtained_marks 
                               FROM subjects s 
                               LEFT JOIN marks_entry m ON s.id = m.subject_id AND m.student_id = ? 
                               WHERE s.course_id = ? 
                               ORDER BY s.type, s.subject_name", [$studentId, $student['course_id']]));
        echo "</pre>";
    } else {
        echo "Student not found.";
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>
