<?php
include_once '../php/db_connection.php';

header('Content-Type: application/json');

$response = [
    'success' => false,
    'classes' => []
];

try {
    $query = "SELECT id, class_name FROM classes ORDER BY class_name";
    $stmt = $pdo->prepare($query);
    $stmt->execute();

    $classes = $stmt->fetchAll(PDO::FETCH_ASSOC);
    if ($classes) {
        $response['success'] = true;
        $response['classes'] = $classes;
    } else {
        $response['message'] = 'No classes found';
    }

} catch (PDOException $e) {
    $response['message'] = 'Database error: ' . $e->getMessage();
}

echo json_encode($response);
