/var/www/(Del)pathways.org.hk/MIS_bk/student/students.json.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
$without_send_header 
true;
require_once(
__DIR__ '/../checkuser.php');
$q $_GET['q'];

$sql "
SELECT student.*, student_grade.title AS grade_title
FROM mis_student student
LEFT JOIN mis_student_grade student_grade ON student_grade.id = student.student_grade_id
WHERE student.is_latest = 1 AND student.deleted = 0
    AND CONCAT(student.last_name, ' ', student.first_name, ' ', student.registration_number) LIKE CONCAT('%', ?, '%')
ORDER BY student.last_name, student.first_name, student.registration_number, student.root_id"
;
$parameters = array($q);
$sth Db\Util::execute($dbh$sql$parameters);
$all_students $sth->fetchAll();

$json_students = array();
foreach (
$all_students as $student) {
    
$json_students[] = array(
        
'id' => $student['root_id'],
        
'text' => $student['last_name'] . ' ' $student['first_name'] . ' (' $student['registration_number'] . ') ' $student['grade_title'],
    );
}

echo 
json_encode(array(
    
'results' => $json_students,
));