<?php
// get_students.php

// Include the database connection file
include("includes/db.php");

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['classId'])) {
    $classId = $_POST['classId'];

    // Fetch students based on class
    $fetchStudentsQuery = "SELECT symbol_no, student_id, name FROM students WHERE Class_id = ? order by symbol_no";
    $stmt = $conn->prepare($fetchStudentsQuery);
    $stmt->bind_param('i', $classId);
    $stmt->execute();
    $result = $stmt->get_result();

    // Display input fields for each student
    while ($row = $result->fetch_assoc()) {
        echo '<div class="form-group col-md-8">';
        echo '<label for="atten_day_' . $row['student_id'] . '">' . $row['name'] . '<span style="color:red;"> ' . '   ['. $row[ 'symbol_no'] . ' ]'.  '</span></label>';
        echo '<input type="number" id="atten_day_' . $row['student_id'] . '" name="attendance[' . $row['student_id'] . '][atten_day]" class="form-control" required>';
        echo '</div>';
    
    }

    // Close the prepared statement
    $stmt->close();
} else {
    // Handle invalid requests
    echo "Invalid request!";
}

// Close the database connection
$conn->close();
?>
