<?php
include "connection.php";
header("Content-Type: application/json");

$response = ["status" => false, "data" => []];

try {
    // Get category ID from GET parameters
    if (!isset($_GET['id']) || empty($_GET['id'])) {
        throw new Exception("Category ID is required.");
    }

    $id = intval($_GET['id']); // convert to integer for safety

    // Fetch category by ID
    $rs = Database::search("SELECT * FROM `category` WHERE `id` = '$id'");

    if ($rs->num_rows > 0) {
        $category = $rs->fetch_assoc();
        $response["status"] = true;
        $response["data"] = $category;
    } else {
        $response["message"] = "Category not found.";
    }

} catch (Exception $e) {
    $response["message"] = "Database Error: " . $e->getMessage();
}

echo json_encode($response);
exit;
?>
