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

try {
    // Check if there are any students with NULL or empty group names in class 10 with session 2025
    $stmt = $pdo->prepare("SELECT COUNT(*) as count FROM students WHERE class_id = ? AND session = ? AND status = 'active' AND (group_name IS NULL OR group_name = '')");
    $stmt->execute([10, '2025']);
    $result = $stmt->fetch();
    
    echo "Students with NULL or empty group names in class 10, session 2025: " . $result['count'] . "\n";
    
    // Check what group values exist for this class/session
    $stmt = $pdo->prepare("SELECT DISTINCT group_name FROM students WHERE class_id = ? AND session = ? AND status = 'active' ORDER BY group_name");
    $stmt->execute([10, '2025']);
    $groups = $stmt->fetchAll();
    
    echo "Existing group names in class 10, session 2025:\n";
    foreach ($groups as $group) {
        $display = ($group['group_name'] === null) ? 'NULL' : "'" . $group['group_name'] . "'";
        echo "- " . $display . "\n";
    }
    
    // Check the exam's group_name value
    $stmt = $pdo->prepare("SELECT id, name, group_name FROM exams WHERE id = ?");
    $stmt->execute([68]);
    $exam = $stmt->fetch();
    
    if ($exam) {
        $exam_group = ($exam['group_name'] === null) ? 'NULL' : "'" . $exam['group_name'] . "'";
        echo "\nExam group_name: " . $exam_group . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>