<?php

require_once '../../../config.php';

$conn = getDBConnection();



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



$query = "SELECT id, subject_name, subject_code FROM subjects WHERE active = 'yes' ORDER BY subject_name";

$result = $conn->query($query);



if ($result) {

    while ($row = $result->fetch_assoc()) {

        $response['subjects'][] = [

            'id' => $row['id'],

            'subject_name' => $row['subject_name'],

            'subject_code' => $row['subject_code']

        ];

    }

    $response['success'] = true;

}



$conn->close();

echo json_encode($response);