<?php
require_once(__DIR__ . '/../config.php');

header('Content-Type: application/json');

if (isset($_GET['module_id']) && is_numeric($_GET['module_id'])) {

    $stmt = $pdo->prepare("SELECT id, unit_name FROM units WHERE module_id = ?");
    $stmt->execute([$_GET['module_id']]);

    echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} else {
    echo json_encode([]);
}