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

echo "<h2>Group Name Comparison Test</h2>";

// Test different group name variations
$testGroups = ['Science', 'SCIENCE', 'science', 'Arts', 'ARTS', 'arts'];

echo "<h3>Testing subject_mark_distribution table:</h3>";
foreach ($testGroups as $group) {
    echo "<p>Searching for group: <strong>$group</strong></p>";
    
    // Test the fixed query
    $stmt = $pdo->prepare("
        SELECT * FROM subject_mark_distribution 
        WHERE subject_id = ? AND class_id = ? AND session = ? AND exam_type = ?
        AND (group_name = ? OR UPPER(group_name) = UPPER(?))
        LIMIT 1
    ");
    $stmt->execute([3, 11, '2024', 'midterm', $group, $group]);
    $result = $stmt->fetch();
    
    if ($result) {
        echo "<p style='color: green;'>✓ Found match: {$result['group_name']}</p>";
    } else {
        echo "<p style='color: red;'>✗ No match found</p>";
    }
}

echo "<h3>Testing students table:</h3>";
foreach ($testGroups as $group) {
    echo "<p>Searching for students in group: <strong>$group</strong></p>";
    
    // Test the fixed query for students
    $stmt = $pdo->prepare("
        SELECT id, first_name, group_name FROM students 
        WHERE class_id = ? AND session = ? 
        AND (group_name = ? OR UPPER(group_name) = UPPER(?))
        LIMIT 3
    ");
    $stmt->execute([11, '2024', $group, $group]);
    $results = $stmt->fetchAll();
    
    if (!empty($results)) {
        foreach ($results as $student) {
            echo "<p style='color: green;'>✓ Found student: {$student['first_name']} (Group: {$student['group_name']})</p>";
        }
    } else {
        echo "<p style='color: red;'>✗ No students found</p>";
    }
}

echo "<p><a href='marks/entry.php'>← Back to Marks Entry</a></p>";
?>