<?php

include './login/connect.php';


$class_id = $_GET['class_id'];
$data = [];

// Fetch students based on the class
$stmt = $conn->prepare("SELECT id, name FROM students WHERE class_id = ?");
$stmt->bind_param("i", $class_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $data['students'] = $result->fetch_all(MYSQLI_ASSOC);
}

echo json_encode($data);

$stmt->close();
$conn->close();
?>
