-
Notifications
You must be signed in to change notification settings - Fork 0
/
autosuggest.php
40 lines (34 loc) · 886 Bytes
/
autosuggest.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
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require "pdo.php";
if(!isset($_REQUEST['term'])){
exit();
}
$searchq = $_REQUEST['term'];
if (strlen($searchq) > 2){
$sql_search = '
SELECT `Last Name`,`First Name`,`Student ID`
FROM students14_15
WHERE `First Name` LIKE "%'.$searchq.'%"
or `Last Name` LIKE "%'.$searchq.'%"
or concat(`First Name`, " " , `Last Name`) LIKE "%'.$searchq.'%"
or concat(`Last Name`, " " , `First Name`) LIKE "%'.$searchq.'%"
';
$stmt_search = $pdo->query($sql_search);
$totalrows = $stmt_search->rowCount();
if($totalrows == 0){
$output = 'There was no search results!';
}else{
$data= array();
while ($result = $stmt_search->fetch(PDO::FETCH_ASSOC)) {
$Sname = $result['First Name'].' '.$result['Last Name'];
$Searchid = $result['Student ID'];
$data[] = array(
'label' => $Sname,
'value' => $Searchid
);
}
}
}
echo json_encode($data);
flush();
?>