<?php
require 'db.php';

$category_id = intval($_POST['category_id'] ?? 0);

if(!$category_id){
    echo '<option value="">Select Subcategory</option>';
    exit;
}

$q = mysqli_query($conn,"
    SELECT id,name 
    FROM subcategories 
    WHERE category_id=$category_id 
    AND status='active'
    ORDER BY sort_order ASC
");

echo '<option value="">Select Subcategory</option>';

while($row = mysqli_fetch_assoc($q)){
    echo "<option value='{$row['id']}'>{$row['name']}</option>";
}