<?php
// filepath: c:\xampp\htdocs\vc\01\results.php
require_once 'config.php';

// Fetch results grouped by date
$results = [];
$sql = "SELECT result_date, game, result_number FROM results ORDER BY result_date DESC";
if ($res = mysqli_query($link, $sql)) {
    while ($row = mysqli_fetch_assoc($res)) {
        $date = date('d-m-Y', strtotime($row['result_date']));
        $results[$date][$row['game']] = $row['result_number'];
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Result Chart</title>
</head>
<body>
    <?php include 'header.php'; ?>
   <section class="result-table-section" style="margin:32px auto; max-width:1100px;">
    <div style="background:#005c97; color:#fff; font-size:1.18rem; font-weight:500; text-align:center; padding:14px 8px; border-radius:12px 12px 0 0;">
        Shubank Result Chart 
    </div>
    <div style="overflow-x:auto;">
        <table class="result-table" style="width:100%; border-collapse:collapse; background:#fff;">
            <thead>
                <tr style="background:#ffd600;">
                    <th style="color:#e53935; font-weight:600; padding:12px 6px;">DATE</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">DISAWAR</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">DL BAZAAR</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">SHRI GANESH</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">FARIDABAD</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">GHAZIABAD</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">RADHEY RADHEY</th>
                    <th style="color:#222; font-weight:600; padding:12px 6px;">GALI</th>
                </tr>
            </thead>
            <tbody>
                <?php
                // List of games in order as table columns
                $games = ['disawar', 'dl_bazaar', 'shri_ganesh', 'faridabad', 'ghaziabad', 'radhey_radhey', 'gali'];
                foreach ($results as $date => $row) {
                    echo '<tr>';
                    echo '<td style="color:#e53935; font-weight:500;">' . $date . '</td>';
                    foreach ($games as $game) {
                        echo '<td>' . htmlspecialchars($row[$game] ?? '-') . '</td>';
                    }
                    echo '</tr>';
                }
                ?>
            </tbody>
        </table>
    </div>
</section>
<?php include 'footer.php'; ?>
</body>
</html>