<?php
require 'includes/db_connect.php';
header('Content-Type: application/json');

$association_id = intval($_GET['association_id'] ?? 0);

if (!$association_id) {
    echo json_encode([]);
    exit();
}

$result = mysqli_query($conn,
    "SELECT full_name, position, phone FROM officials
     WHERE association_id = $association_id
     ORDER BY id ASC"
);

$officials = [];
while ($row = mysqli_fetch_assoc($result)) {
    $officials[] = $row;
}

echo json_encode($officials);