File "read_single.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/qp_setters/read_single.php
File size: 1.41 KiB (1441 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once '../../config/config.php';
header('Content-Type: application/json');

try {
    $id = (int)($_GET['id'] ?? 0);
    if ($id <= 0) { echo json_encode(['status'=>'error','message'=>'Invalid id']); exit; }

    $st = $pdo->prepare("SELECT qps.*, e.exam_name, CONCAT(s.first_name,' ',s.last_name) AS staff_name, qp.pattern_name,
                                es.exam_subject_id, subj.subject_code, subj.subject_name,
                                t.template_id, t.template_name
                         FROM qp_setter_assignments qps
                         JOIN exams e ON qps.exam_id = e.exam_id
                         JOIN staff s ON qps.staff_id = s.staff_id
                         LEFT JOIN question_patterns qp ON qps.pattern_id = qp.pattern_id
                         LEFT JOIN exam_subjects es ON es.exam_subject_id = qps.exam_subject_id
                         LEFT JOIN subjects subj ON es.subject_id = subj.subject_id
                         LEFT JOIN question_pattern_templates t ON t.template_id = qps.template_id
                         WHERE qps.id = ?");
    $st->execute([$id]);
    $row = $st->fetch(PDO::FETCH_ASSOC);
    if (!$row) { echo json_encode(['status'=>'error','message'=>'Not found']); exit; }
    echo json_encode(['status'=>'success','data'=>$row]);
} catch (Throwable $e) {
    http_response_code(500);
    echo json_encode(['status'=>'error','message'=>$e->getMessage()]);
}
?>


PHP File Manager