<?php
include('includes/dbconnection.php');

if (isset($_POST['class_name']) && isset($_POST['section'])) {
    $class_name = $_POST['class_name'];
    $section = $_POST['section'];

    $subjects_result = $con->query("SELECT id, Subject_name FROM subjectcombination WHERE Class = '$class_name' AND section = '$section'");

    if ($subjects_result->num_rows > 0) {
        while ($subject = $subjects_result->fetch_assoc()) {
            echo '<div class="form-check">
                    <input type="checkbox" class="form-check-input" name="subjects[]" value="'.$subject['id'].'" id="subject'.$subject['id'].'">
                    <label class="form-check-label" for="subject'.$subject['id'].'">'.$subject['Subject_name'].'</label>
                  </div>';
        }
    } else {
        echo '<p>No subjects found for this class and arm.</p>';
    }
}
?>
