<?php

require_once "config.php";

header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
    case 'GET':
        if (isset($_GET['kategori'])) {
            $kategori = $_GET['kategori'];
            
            $query = $conn->prepare("SELECT * FROM urlcafe WHERE kategori = ?");
            $query->bind_param('s', $kategori);
            $query->execute();
            $result = $query->get_result();
            $data = $result->fetch_all(MYSQLI_ASSOC); 
            echo json_encode($data);
        } else {
            echo json_encode(array('error' => 'Parameter "kategori" is required.'));
        }
        break;
}

mysqli_close($conn);
?>
