-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.php
69 lines (58 loc) · 1.79 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
61
62
63
64
65
66
67
68
69
<?php
// Global database/session initialization.
require_once "./config.php";
if(!isset($_SESSION['loggedin'])){
header("Location: ./login.php");
exit;
}
?>
<html>
<head>
<title>Home - Nilamark</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.svg">
<link rel="manifest" href="pwa-manifest.json">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php include 'header.php'; ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
function delay(fn, ms) {
let timer = 0
return function(...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
$(document).ready(function(){
$('#search').keyup(delay(function(){
var searchQuery = $('#search').val();
searchData(1, searchQuery);
console.log("searched");
}, 250));
});
function searchData(page, searchQuery = '') {
$.ajax({
url:"load-search.php",
method:"POST",
data:{search:'search', page:page, searchQuery:searchQuery}, success:function(data) {
$('#searchResult').html(data);
}
});
}
$('#searchSection').on('click', '.page-link', function(){
var page = $(this).data('page_number');
var searchQuery = $('#search').val();
searchData(page, searchQuery);
});
</script>
<div class="card-body" id="searchSection">
<div class="form-group">
<input type="text" name="search" id="search" class="form-control" placeholder="Type your search keyword here" />
</div>
<div class="table-responsive" id="searchResult"></div>
</div>
<?php require_once "./footer.php"; ?>
</body>
</html>