<?php

require_once '../../../config.php';

$conn = getDBConnection();



$class = $_POST['class'] ?? '';



$stmt = $conn->prepare("SELECT id, student_id, first_name, last_name FROM students WHERE class = ? AND status = 'active' ORDER BY first_name, last_name");

$stmt->bind_param("s", $class);

$stmt->execute();

$result = $stmt->get_result();



$output = '';

while ($row = $result->fetch_assoc()) {

    $output .= '<option value="' . $row['id'] . '">' . htmlspecialchars($row['first_name'] . ' ' . $row['last_name']) . ' (' . $row['student_id'] . ')</option>';

}



$stmt->close();

$conn->close();



echo $output;



