<?php
require 'config.php';


$teacher = $_GET['teacher'];
$term = $_GET['term'];
$classes = $_GET['classes'];

$stmt = $conn->prepare("
    SELECT 
        e.Admission_no,
        s.name AS student_name,
        e.subject,
        e.ca_test,
        e.exam_score,
        e.total
    FROM end_term_report e
    LEFT JOIN students s ON e.Admission_no = s.Admission_num
    WHERE e.Teacher = ? AND e.term = ? AND e.classes = ?
    ORDER BY e.Admission_no, e.subject
");
$stmt->bind_param("sss", $teacher, $term, $classes);
$stmt->execute();
$result = $stmt->get_result();

$records = [];
while ($row = $result->fetch_assoc()) {
    $records[] = $row;
}

echo json_encode($records);

