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

try {
    // Get the structure of the results table
    $stmt = $pdo->query("SHOW COLUMNS FROM results");
    $columns = $stmt->fetchAll();
    
    echo "Results table structure:\n";
    foreach ($columns as $column) {
        echo "- " . $column['Field'] . " (" . $column['Type'] . ")\n";
    }
    
    // Check if detailed mark fields exist
    $detailed_fields = ['cq_marks', 'mcq_marks', 'practical_marks', 'assignment_marks', 'attendance_marks'];
    $existing_fields = [];
    
    foreach ($columns as $column) {
        if (in_array($column['Field'], $detailed_fields)) {
            $existing_fields[] = $column['Field'];
        }
    }
    
    echo "\nDetailed mark fields found: " . implode(', ', $existing_fields) . "\n";
    
    // If detailed fields exist, check some sample data
    if (!empty($existing_fields)) {
        $stmt = $pdo->query("SELECT * FROM results LIMIT 1");
        $sample = $stmt->fetch();
        
        if ($sample) {
            echo "\nSample data with detailed marks:\n";
            foreach ($existing_fields as $field) {
                echo "$field: " . ($sample[$field] ?? 'NULL') . "\n";
            }
        }
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>