-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-search.php
27 lines (16 loc) · 664 Bytes
/
api-search.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
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
/*$data = json_decode(file_get_contents("php://input"), true);
$search_value = $data['search'];*/
$search_value = isset($_GET['search']) ? $_GET['search'] : die();
include "config.php";
$sql = "SELECT * FROM students WHERE student_name LIKE '%{$search_value}%'";
$result = mysqli_query($conn, $sql) or die("SQL Query Failed.");
if(mysqli_num_rows($result) > 0 ){
$output = mysqli_fetch_all($result, MYSQLI_ASSOC);
echo json_encode($output);
}else{
echo json_encode(array('message' => 'No Search Found.', 'status' => false));
}
?>