File "read_single.php"
Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/read_single.php
File size: 1.02 KiB (1047 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
require_once '../../config/config.php';
header('Content-Type: application/json');
try {
if (!isset($_GET['id'])) {
echo json_encode(null);
exit;
}
$id = (int)$_GET['id'];
// Get exam_subject data with priority to exam_timetable for dates/sessions
$stmt = $pdo->prepare("
SELECT es.*,
COALESCE(et.exam_date, es.exam_date) as exam_date,
COALESCE(et.session, es.session) as session,
s.course_id,
c.course_name
FROM exam_subjects es
LEFT JOIN exam_timetable et ON et.exam_subject_id = es.exam_subject_id
JOIN subjects s ON s.subject_id = es.subject_id
JOIN courses c ON c.course_id = s.course_id
WHERE es.exam_subject_id = ?
LIMIT 1
");
$stmt->execute([$id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode($result ?: null);
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
?>