<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Consulta Pega 3</title>
</head>
<body>
    <h1>Consulta Pega 3</h1>
    <form method="GET" action="">
        <label for="dia">Selecciona el día:</label>
        <select name="dia" id="dia">
            <option value="sabado">Sábado</option>
            <option value="martes">Martes</option>
            <option value="sabado_martes">Sábado y Martes</option>
        </select>

        <label for="mes">Selecciona el mes:</label>
        <select name="mes" id="mes">
            <?php
                // Conexión a la base de datos
                $servername = "localhost";
                $username = "lotto";
                $password = "12Qwaszx**";
                $dbname = "lotto";
                
                // Crear conexión
                $conn = new mysqli($servername, $username, $password, $dbname);
                if ($conn->connect_error) {
                    die("Conexión fallida: " . $conn->connect_error);
                }

                // Obtener todos los meses distintos
                $query = "SELECT DISTINCT MONTH(fecha) AS mes FROM lotto ORDER BY mes";
                $result = $conn->query($query);
                while ($row = $result->fetch_assoc()) {
                    echo "<option value='" . $row['mes'] . "'>" . date("F", mktime(0, 0, 0, $row['mes'], 10)) . "</option>";
                }
                $conn->close();
            ?>
        </select>

        <label for="anio">Selecciona el año:</label>
        <select name="anio" id="anio">
            <?php
                // Reabrir la conexión a la base de datos
                $conn = new mysqli($servername, $username, $password, $dbname);
                if ($conn->connect_error) {
                    die("Conexión fallida: " . $conn->connect_error);
                }

                // Obtener todos los años distintos
                $query = "SELECT DISTINCT YEAR(fecha) AS anio FROM lotto ORDER BY anio";
                $result = $conn->query($query);
                while ($row = $result->fetch_assoc()) {
                    echo "<option value='" . $row['anio'] . "'>" . $row['anio'] . "</option>";
                }
                $conn->close();
            ?>
        </select>

        <button type="submit">Consultar</button>
    </form>
</body>
</html>
