File "read_by_exam.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/exam_subjects/read_by_exam.php
File size: 1.65 KiB (1686 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
// api/exam_subjects/read_by_exam.php
header('Content-Type: application/json');
require_once '../../config/config.php';
try {
$exam_id = $_GET['exam_id'] ?? '';
if (empty($exam_id)) {
echo json_encode([
'status' => 'error',
'message' => 'Exam ID is required'
]);
exit;
}
$sql = "SELECT
es.exam_subject_id,
es.exam_id,
es.max_marks,
es.pass_marks,
es.exam_date,
es.session,
s.subject_id,
s.subject_code,
s.subject_name,
s.semester,
s.type,
e.exam_name,
e.academic_year,
e.semester as exam_semester,
COUNT(sr.registration_id) as total_registrations
FROM exam_subjects es
JOIN subjects s ON es.subject_id = s.subject_id
JOIN exams e ON es.exam_id = e.exam_id
LEFT JOIN student_registrations sr ON es.exam_subject_id = sr.exam_subject_id
WHERE es.exam_id = :exam_id
GROUP BY es.exam_subject_id
ORDER BY s.subject_code ASC";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':exam_id', $exam_id);
$stmt->execute();
$subjects = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'data' => $subjects
]);
} catch (Exception $e) {
echo json_encode([
'status' => 'error',
'message' => 'Error: ' . $e->getMessage()
]);
}
?>