-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
60 lines (37 loc) · 1.13 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
#SET HEADERS
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require_once("database.php");
$database = new Database();
$conn = $database->connect();
$msg['message'] = '';
if(isset($_GET['q'])){
$search = $_GET['q'];
$sql = "SELECT * FROM task WHERE title LIKE '%$search%'";
$stmt = $conn->prepare($sql);
$stmt->execute();
if($stmt->rowCount() !== 0){
$allTask = [];
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($row as $r) {
$singlePost = [
"id" => $r['id'],
"title" => $r['title'],
"description" => $r['description'],
"priority" => $r['priority']
];
array_push($allTask, $singlePost);
}
echo json_encode($allTask);
} else {
$msg['message'] = "Task no found";
echo json_encode($msg);
}
} else{
$msg['message'] = "Any";
echo json_encode($msg);
}