-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
112 lines (101 loc) · 5.31 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
<?php
include 'header.php';
include("config.php");
$limit = 3;
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
if (isset($_GET['search'])) {
$search = $_GET['search'];
}
?>
<div id="main-content">
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- post-container -->
<div class="post-container">
<h2 class="page-heading">Search : <?php echo $search; ?></h2>
<?php
$sql = "SELECT post.post_id,post.author, post.title,post.category,post.description,post.post_img, category.category_name, post.post_date,user.username FROM post
LEFT JOIN category ON post.category = category.category_id
LEFT JOIN user ON post.author = user.user_id
WHERE post.title LIKE '%$search%' OR post.description LIKE '%$search%'
ORDER BY post_id DESC LIMIT 0,3";
$result = mysqli_query($conn, $sql) or die("Query Error");
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<div class="post-content">
<div class="row">
<div class="col-md-4">
<a class="post-img" href="single.php?id=<?php echo $row['post_id']; ?>"><img c src="admin/upload/<?php echo $row['post_img']; ?>" alt="" /></a>
</div>
<div class="col-md-8">
<div class="inner-content clearfix">
<h3><a href='single.php?id=<?php echo $row['post_id']; ?>'><?php echo $row['title']; ?></a></h3>
<div class="post-information">
<span>
<i class="fa fa-tags" aria-hidden="true"></i>
<a href='category.php?id=<?php echo $row['category']; ?>'><?php echo $row['category_name']; ?></a>
</span>
<span>
<i class="fa fa-user" aria-hidden="true"></i>
<a href='author.php?id=<?php echo $row['author']; ?>'><?php echo $row['username']; ?></a>
</span>
<span>
<i class="fa fa-calendar" aria-hidden="true"></i>
<?php echo $row['post_date']; ?>
</span>
</div>
<p class="description">
<?php echo substr($row['description'], 0, 130); ?>
</p>
<a class='read-more pull-right' href='single.php?id=<?php echo $row['post_id']; ?>'>read more</a>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<ul class='pagination'>
<?php
$sql_1 = "SELECT title, description FROM post WHERE post.title LIKE '%$search%' OR post.description LIKE '%$search%' ";
$result_1 = mysqli_query($conn, $sql_1) or die("Query Faild");
if (mysqli_num_rows($result) > 0) {
$row = mysqli_num_rows($result_1);
$total_pages = ceil($row / $limit);
}
?>
<?php
if ($page > 1) {
?>
<li><a href="search.php?apge=<?php echo $page - 1; ?>&search=<?php echo $search; ?>">Prev</a></li>
<?php
}
for ($i = 1; $i <= $total_pages; $i++) {
?>
<li><a href="search.php?page=<?php echo $i; ?>&search=<?php echo $search; ?>"><?php echo $i; ?></a></li>
<?php
}
if ($total_pages > $page) {
?>
<li><a href="search.php?page=<?php echo $page + 1; ?>&search=<?php echo $search; ?>">Next</a></li>
<?php
}
?>
<!-- <li class="active"><a href="">1</a></li>
<li><a href="">2</a></li>
<li><a href="">3</a></li> -->
</ul>
</div><!-- /post-container -->
</div>
<?php include 'sidebar.php'; ?>
</div>
</div>
</div>
<?php include 'footer.php'; ?>