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

try {
    // Test with student_id=6279
    $stmt = $pdo->prepare('SELECT first_name, last_name FROM students WHERE id = ?');
    $stmt->execute([6279]);
    $student = $stmt->fetch();

    if ($student) {
        echo 'Student found: ' . $student['first_name'] . ' ' . $student['last_name'] . "\n";

        // Check Bangla subjects
        $stmt = $pdo->prepare('SELECT r.*, sub.name FROM results r JOIN subjects sub ON r.subject_id = sub.id WHERE r.student_id = ? AND (sub.name LIKE "%বাংলা%" OR sub.name LIKE "%Bangla%")');
        $stmt->execute([6279]);
        $bangla_subjects = $stmt->fetchAll(PDO::FETCH_ASSOC);

        echo 'Bangla subjects: ' . count($bangla_subjects) . "\n";
        $total_bangla = 0;
        foreach ($bangla_subjects as $subject) {
            echo '- ' . $subject['name'] . ': ' . $subject['marks_obtained'] . " marks\n";
            $total_bangla += $subject['marks_obtained'];
        }
        echo 'Total Bangla marks: ' . $total_bangla . "\n\n";

        // Check English subjects
        $stmt = $pdo->prepare('SELECT r.*, sub.name FROM results r JOIN subjects sub ON r.subject_id = sub.id WHERE r.student_id = ? AND (sub.name LIKE "%ইংরেজি%" OR sub.name LIKE "%English%")');
        $stmt->execute([6279]);
        $english_subjects = $stmt->fetchAll(PDO::FETCH_ASSOC);

        echo 'English subjects: ' . count($english_subjects) . "\n";
        $total_english = 0;
        foreach ($english_subjects as $subject) {
            echo '- ' . $subject['name'] . ': ' . $subject['marks_obtained'] . " marks\n";
            $total_english += $subject['marks_obtained'];
        }
        echo 'Total English marks: ' . $total_english . "\n\n";

    } else {
        echo 'Student not found\n';
    }

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