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

if (isset($_POST['classId'])) {
    $classId = $_POST['classId'];
    $query = "SELECT student_id, name FROM students WHERE class_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $classId);
    $stmt->execute();
    $result = $stmt->get_result();
    echo "<option value=''>Select Student</option>";
    while ($row = $result->fetch_assoc()) {
        echo "<option value='{$row['student_id']}'>{$row['name']}</option>";
    }
    $stmt->close();
}
$conn->close();
?>
