<?php
include_once('../../includes/db.php');

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

$category_id = $_GET['category_id'] ?? null;

if ($category_id) {
    $category_id = intval($category_id);
    $products = fetchAll("SELECT * FROM products WHERE category_id = $category_id ORDER BY id DESC");

    echo json_encode([
        "status" => true,
        "data" => $products
    ]);
} else {
    echo json_encode([
        "status" => false,
        "message" => "Missing category ID."
    ]);
}
