<?php
include("config.php");

if (isset($_POST['country_id'])) {
    $country_id = $_POST['country_id'];
    $stmt = $conn->prepare("SELECT id, name FROM leagues WHERE country_id = ? ORDER BY name ASC");
    $stmt->bind_param("i", $country_id);
    $stmt->execute();
    $result = $stmt->get_result();

    echo '<option value="">Select League</option>';
    while ($row = $result->fetch_assoc()) {
        echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
}
?>
