<?php
include 'db.php';

$category_id = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 0;
$options = '';

if ($category_id > 0) {
    $result = $conn->query("SELECT id, name FROM sub_categories WHERE category_id = $category_id ORDER BY name ASC");
    while ($row = $result->fetch_assoc()) {
        $options .= "<option value='{$row['id']}'>{$row['name']}</option>";
    }
}

echo $options ?: "<option value=''>No sub-categories</option>";
?>
