<?php
session_start();
include '../admin/includes/database.php';
include '../admin/includes/functions.php';
$conn= new Functions();

if (!empty($_POST['classesID']) AND !empty($_POST['teacher_name'])) {
    $classID = $_POST['classesID'];
    $teacher_name = $_POST['teacher_name'];

    //fetch student's data based on the specific class
    $sql = "SELECT * FROM sections WHERE class = :classID AND teacher_name =:teacher_name ORDER BY name";
    $conn->query($sql);
    $conn->bind(":classID", $classID);
    $conn->bind(":teacher_name", $teacher_name);
    //generate HTML of student option
    if ($conn->rowCount() > 0) {
        $result = $conn->fetchMultiple();

        ?>
        <option value=''>Select Section</option><?php
        foreach ($result as $section) {
            $section_name = $section->name;
            ?>
            <option value="<?php echo $section->id; ?>"><?php echo $section_name; ?></option><?php
        }
    } else {
        echo "<option value=''>Section not found.</option>";
    }
} else {
    echo "<option value=''>error occurred.</option>";
}
