<?php
header("Content-Type: application/json");
require("../includes/config.php");

$stmt = $pdo->prepare("
    SELECT 
        c.id,
        c.chapter_name,
        c.chapter_order,
        c.status,
        s.subject_name
    FROM chapters c
    JOIN subjects s ON s.id = c.subject_id
    ORDER BY c.chapter_order ASC
");

$stmt->execute();
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));


 
