<?php
require_once __DIR__ . "/../config/db.php";

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

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

$result = mysqli_query($conn, "
    SELECT name 
    FROM categories 
    WHERE department_id = $dept_id 
    ORDER BY name ASC
");

$data = [];

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

echo json_encode($data);