<?php

// Enable CORS headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type");

require_once 'db.php';
$sub_cat = $_REQUEST['sub_cat'];

// Query the database to get all active districts
$query = "SELECT * FROM question_sub_cats WHERE  ques_sc_parent = '$sub_cat' and status = 'Active'";
$stmt = $pdo->prepare($query);
$stmt->execute();

// Fetch all matching districts
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

if ($data) {
    // If districts are found
    $response = [
        'success' => true,
        'message' => 'Retrieved',
        'datas' => $data  // Return all districts in an array
    ];
} else {
    // No districts found
    $response = [
        'success' => false,
        'message' => 'No active districts found',
    ];
}

// Send the response as JSON
header('Content-Type: application/json');
echo json_encode($response);

?>
