<?php
require_once 'config.php'; // Adjust path as needed
header('Content-Type: application/json');

$subject_id = isset($_GET['subject_id']) ? intval($_GET['subject_id']) : 0;
$papers = [];

if ($subject_id > 0 && isset($conn) && $conn instanceof mysqli) {
    $sql = "SELECT id, paper_number, paper_name, max_score FROM subject_papers WHERE subject_id = ? ORDER BY paper_number ASC";
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("i", $subject_id);
        $stmt->execute();
        $result = $stmt->get_result();
        while ($row = $result->fetch_assoc()) {
            $papers[] = $row;
        }
        $stmt->close();
    }
    $conn->close();
}
echo json_encode($papers);
?>