<?php
include("includes/db.php");

if (isset($_POST["classId"])) {
    $classId = $conn->real_escape_string($_POST["classId"]);

    // Fetch students based on the selected class
    $query = "SELECT * FROM students WHERE class_id = '$classId'";
    $result = $conn->query($query);

    $options = "<option value=''>Select Student</option>"; // Initialize options
    while ($row = $result->fetch_assoc()) {
        $options .= "<option value='{$row['student_id']}'>{$row['name']}</option>";
    }

    echo $options;
}
?>
