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

$stmt = $pdo->prepare("
    SELECT topics.id, topics.name AS topic_name, categories.name AS category_name, topics.status 
    FROM topics 
    JOIN categories ON topics.category_id = categories.id 
    ORDER BY categories.name, topics.name
");
$stmt->execute();
$topics = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($topics);
?>