<?php
// Include database connection code
include("includes/db.php");

// Check if class_id is provided in the query parameters
if(isset($_GET['class_id'])) {
    $classId = $_GET['class_id'];

    // Query subjects based on the provided class_id
    $subjectsQuery = "SELECT subjects.id, subjects.subject_name
                     FROM class_subject_mapping
                     INNER JOIN subjects ON class_subject_mapping.subject_id = subjects.id
                     WHERE class_subject_mapping.class_id = $classId";

    $subjectsResult = $conn->query($subjectsQuery);

    // Prepare data for JSON response
    $subjects = [];
    while ($row = $subjectsResult->fetch_assoc()) {
        $subjects[] = $row;
    }

    // Return subjects data as JSON
    echo json_encode($subjects);

    // Close the database connection
    $conn->close();
} else {
    // Handle the case where class_id is not provided in the query parameters
    echo json_encode(["error" => "Class ID not provided"]);
}
?>
