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

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

    // Fetch subjects for the selected student's class
    $query = "SELECT subjects.id, subjects.subject_name 
              FROM class_subject_mapping 
              INNER JOIN subjects ON class_subject_mapping.subject_id = subjects.id 
              WHERE class_subject_mapping.class_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $classId);
    $stmt->execute();
    $result = $stmt->get_result();

    $output = "";
    while ($row = $result->fetch_assoc()) {
        $subjectId = $row['id'];
        $subjectName = $row['subject_name'];

        // HTML for the subject with marks input field
        $output .= "
            <div class='form-group col-md-5'>
                <label for='marks_$subjectId'>$subjectName:</label>
                <input style='width:250px' type='number' class='form-control marks-input' name='marks[$subjectId]' id='marks_$subjectId' placeholder='Enter marks for $subjectName' data-subject-id='$subjectId'>
            </div>
        ";
    }

    echo $output;
}
?>
