-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
194 lines (169 loc) · 6.69 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php require 'inc/header.php';?>
<?php
$search = mysqli_real_escape_string($db->link, $_GET['search']);
$submit = mysqli_real_escape_string($db->link, $_GET['submit']);
if (!isset($search) || $search == NULL) {
header("Location: 404.php");
} else {
$search = $search;
$submit = $submit;
}
?>
<!--======================= Main Section Start ======================= -->
<section class="main_section">
<div class="mainsection_bfr_container">
<div class="container">
<div class="main_section_aftr_row clearfix">
<div class="row">
<div class="col-md-8 left_main_Content col-sm-12">
<!-- Pagination -->
<?php
$per_page = 3;
if (isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}
$start_form = ($page - 1) * $per_page;
?>
<!-- Pagination -->
<?php
$query = "SELECT * FROM tbl_post WHERE title LIKE '%$search%' OR body LIKE '%$search%' LIMIT $start_form,$per_page";
$search_post = $db->select($query);
if ($search_post) {
while ($result = $search_post->fetch_assoc()) {?>
<div class="my_card my_card_post clearfix">
<a href="post.php?postid=<?php echo $result['id']; ?>"><h2><?php echo $result["title"]; ?></h2></a>
<h5><?php echo $fm->date($result['date']); ?></h5>
<div class="fakeimg height_img">
<a href="post.php?postid=<?php echo $result['id']; ?>"><img src="admin/uploads/<?php echo $result["image"]; ?>" alt=""></a>
</div>
<h6 class="remove_cls">Author: <a href=""><?php echo $result["author"]; ?></a></h6>
<?php echo $fm->textShorten($result["body"], 270); ?><a href="post.php?postid=<?php echo $result['id']; ?>" class="read_more">Read More <i class="fa fa-angle-double-right"></i></a>
</div>
<?php }} else {?>
<div class="my_card">
<h2 class="mt-1">Your Search Query Not Found !!.</h2>
</div>
<?php }?>
<?php
$row_query = "SELECT * FROM tbl_post WHERE title LIKE '%$search%' OR body LIKE '%$search%' LIMIT $start_form,$per_page";
$row_categories = $db->select($row_query);
if ($row_categories == true) {?>
<!-- Pagination -->
<div class="my_card my_card_post clearfix">
<div class="pagination">
<?php
$pagination_query = "SELECT * FROM tbl_post WHERE title LIKE '%$search%' OR body LIKE '%$search%' ";
$pagination_result = $db->select($pagination_query);
$total_rows = mysqli_num_rows($pagination_result);
$total_pages = ceil($total_rows / $per_page);
echo "<a href='search.php?search=$search&submit=$submit'>First Page</a>";
for ($i = 1; $i <= $total_pages; $i++) {
echo "<a href='search.php?search=$search&submit=$submit&page=$i'>" . $i . "</a>";
}
echo "<a href='search.php?search=$search&submit=$submit&page=$total_pages'>Last Page</a>";
?>
</div>
</div>
<?php }?>
<!-- Pagination -->
</div>
<?php require 'inc/sidebar.php'?>
</div>
</div>
</div>
</div>
</section>
<!--======================= Main Section End======================== -->
<?php require 'inc/footer.php'?>
<!--======================= Header Script Start======================== -->
<script>
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
<script>
/* Open when someone clicks on the span element */
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
/* Close when someone clicks on the "x" symbol inside the overlay */
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
<!--======================= Header Script Start======================== -->
<!--===================== Hero Section Script Start==================== -->
<script>
var slideIndex = 1;
showSlides_one(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides_one(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides_one(slideIndex = n);
}
function showSlides_one(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
}
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) { slideIndex = 1 }
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
setTimeout(showSlides, 5000); // Change image every 2 seconds
}
</script>
<!--===================== Hero Section Script End====================== -->
<!--=================== Sticy Header ==================== -->
<script>
window.onscroll = function () { myFunction() };
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
</script>
<!--=================== Sticy Header ==================== -->
<!--=================== Scroll To Top ==================== -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="js/scrolltop.js"></script>
<!--=================== Scroll To Top==================== -->
</body>
</html>