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

$stmt = $pdo->prepare("
    SELECT c.id, c.name, t.status 
    FROM categories c 
    LEFT JOIN topics t ON c.id = t.category_id 
    GROUP BY c.id, c.name
");
$stmt->execute();
$categories = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($categories);
?>