-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
151 lines (119 loc) · 6.99 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
<?php include "includes/header.php" ?>
<!-- Blog-->
<section class="module">
<div class="container">
<div class="row">
<div class="col-lg-8">
<!-- Post-->
<?php
if (isset($_POST['submit'])) {
$search = mysqli_real_escape_string($connection, $_POST['search']);
$query = "SELECT * FROM posts WHERE post_tags LIKE '%$search%' ";
$search_query = mysqli_query($connection, $query);
if (!$search_query) {
die("QUERY FAILED " . mysqli_error($connection));
}
$count = mysqli_num_rows($search_query);
if ($count == 0) {
echo "<div class='alert alert-danger'>
<strong>0</strong> results found.
</div>
";
return false;
} else {
echo
<div class='alert alert-success'>
<strong>{$count}</strong> result(s) found.
</div>
";
while ($row = mysqli_fetch_assoc($search_query)) {
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_author = $row['post_author'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'], 0, 200);
$post_tags = $row['post_tags'];
$post_status = $row['post_status'];
$post_description = $row['post_description'];
if ($post_status == 'published') {
?>
<article class="post">
<div class="post-preview"><a href="post/<?php echo $post_id ?>"><img src="images/<?php echo imagePlaceholder($post_image); ?>" alt="Post Image"></a></div>
<div class="post-wrapper">
<div class="post-header">
<h2 class="post-title"><a href="post/<?php echo $post_id ?>"><?php echo $post_title ?></a>
</h2>
<ul class="post-meta">
<li><?php echo $post_date ?></li>
<li><?php echo $post_tags ?></li>
<li>By
<a href="/blog/author_posts.php?author=<?php echo $post_author ?>&p_id=<?php echo $post_id ?>"><?php echo $post_author ?></a>
</li>
</ul>
</div>
<div class="post-content">
<p><?php echo $post_description ?></p>
</div>
<br>
<div class="post-more"><a class="btn btn-brand btn-sm" href="post/<?php echo $post_id ?>">Read More</a>
</div>
</div>
</article>
<!-- Post end-->
<!-- Page Navigation-->
<div class="row">
<div class="col-md-12">
<nav>
<ul class="pagination justify-content-center">
<li class="page-item"><a class="page-link" href="#"><span class="fas fa-angle-left"></span></a></li>
<li class="page-item active"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">4</a></li>
<li class="page-item"><a class="page-link" href="#"><span class="fas fa-angle-right"></span></a></li>
</ul>
</nav>
</div>
</div>
<!-- Page Navigation end-->
<?php }
}
}
if ($_SESSION['user_role'] == 'admin' && $post_status !== 'published') {
?>
<article class="post">
<div class="post-preview"><a href="post/<?php echo $post_id ?>"><img src="images/<?php echo imagePlaceholder($post_image); ?>" alt="Post Image"></a></div>
<div class="post-wrapper">
<div class="post-header">
<h2 class="post-title"><a href="post/<?php echo $post_id ?>"><?php echo $post_title ?></a> <a class="badge badge-secondary" href="#"><?php echo $post_status ?></a>
</h2>
<ul class="post-meta">
<li><?php echo $post_date ?></li>
<li><?php echo $post_tags ?></li>
<li>By
<a href="/blog/author_posts.php?author=<?php echo $post_author ?>&p_id=<?php echo $post_id ?>"><?php echo $post_author ?></a>
</li>
</ul>
</div>
<div class="post-content">
<p><?php echo $post_description ?></p>
</div>
<br>
<div class="post-more"><a class="btn btn-brand btn-sm" href="post/<?php echo $post_id ?>">Read More</a>
</div>
</div>
</article>
<?php
}
} ?>
</div>
<div class="col-lg-4">
<?php include "includes/navigation.php" ?>
</div>
</div>
</div>
</section>
<!-- Blog end-->
<?php include "includes/footer.php"
?>