<?php
require 'db_connection.php';

$sql = "
    SELECT students.student_id, students.name, users.username, classes.class_name, parents.name AS parent_name
    FROM students
    JOIN users ON students.user_id = users.user_id
    JOIN classes ON students.class_id = classes.class_id
    JOIN parents ON students.parent_id = parents.parent_id
";
$result = $conn->query($sql);
$students = [];

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $students[] = $row;
    }
}

echo json_encode($students);
?>
