-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
executable file
·244 lines (189 loc) · 10.9 KB
/
category.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php include "includes/db.php"; ?>
<?php include "includes/header.php"?>
<?php session_start();?>
<!-- Navigation -->
<?php include "includes/navigation.php"?>
<div id="id01" class="w3-modal">
<div class="w3-modal-content w3-card-4 w3-animate-zoom" style="max-width:600px">
<div class="w3-center"><br>
<span onclick="document.getElementById('id01').style.display='none'" class="w3-button w3-xlarge w3-transparent w3-display-topright" title="Close Modal">×</span>
<img src="images/avatar3.png" alt="Avatar" style="width:30%" class="w3-circle w3-margin-top">
</div>
<form class="w3-container" id="login-form" method="post">
<div class="w3-section">
<h2 class="text-center">Login</h2>
<label><b>Username</b></label>
<input class="w3-input w3-border w3-margin-bottom" type="text" placeholder="Enter Username" name="username" required>
<label><b>Password</b></label>
<input class="w3-input w3-border" type="password" placeholder="Enter Password" name="password" required>
<button class="w3-button w3-block w3-green w3-section w3-padding" type="submit" value="Login" name="login">Login</button>
<!-- <input class="w3-check w3-margin-top" type="checkbox" checked="checked"> Remember me-->
</div>
</form>
<div class="w3-container w3-border-top w3-padding-16 w3-light-grey">
<button onclick="document.getElementById('id01').style.display='none'" type="button" class="w3-button w3-red">Cancel</button>
<span class="w3-right w3-padding w3-hide-small"><a href="forget.php?forgot=<?php echo uniqid(true);?>">Forget password?</a></span>
</div>
</div>
</div>
<section class="section-sm">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="search-result bg-gray">
<?php
if(isset($_GET['category'])) {
$post_category_id = $_GET['category'];
}
$query = "SELECT * FROM posts WHERE post_category_id=$post_category_id";
$select_all_posts_query = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($select_all_posts_query)) {
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_location_id = $row['post_location_id'];
$post_author = $row['post_author'];
$post_category_id = $row['post_category_id'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'], 0, 100);
?>
<?php global $connection;
$query = "SELECT * FROM categories WHERE cat_id={$post_category_id}";
$select_category_id = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($select_category_id)) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<h4>Result For : <?php echo "<td>{$cat_title}</td>"?></h4>
<?php
}
}
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="category-sidebar">
<div class="widget category-list">
<?php
$query = "SELECT * FROM categories";
$select_categories_sidebar = mysqli_query($connection,$query);
?>
<h4 class="widget-header">All Category</h4>
<ul class="category-list">
<?php
while($row = mysqli_fetch_assoc($select_categories_sidebar ))
{
$cat_title = $row['cat_title'];
$cat_id = $row['cat_id'];
echo"<li><a href='category.php?category=$cat_id'>{$cat_title}</a></li>";
}
?>
<h4 class="widget-header">Nearby</h4>
<ul class="category-list">
<?php
$query = "SELECT * FROM location";
$select_location_sidebar = mysqli_query($connection,$query);
?>
<?php
while($row = mysqli_fetch_assoc($select_location_sidebar ))
{
$location_title = $row['location_title'];
$location_id = $row['location_id'];
echo"<li><a href='location.php?location=$location_id'>{$location_title}</a></li>";
}
?>
</ul>
</div>
</div>
</div>
<div class="col-md-9">
<div class="category-search-filter">
<div class="row">
<div class="col-md-6">
<strong>Posts</strong>
</div>
</div>
</div>
<div class="product-grid-list">
<div class="row mt-30">
<?php
if(isset($_GET['category'])) {
$post_category_id = $_GET['category'];
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] == 'admin') {
$query = "SELECT * FROM posts WHERE post_category_id=$post_category_id ORDER BY post_id DESC ";
} else {
$query = "SELECT * FROM posts WHERE post_category_id=$post_category_id AND post_status='published' ORDER BY post_id DESC ";
}
$select_all_posts_query = mysqli_query($connection, $query);
if(mysqli_num_rows($select_all_posts_query) < 1)
{
echo " <h1 class='text-center'>No post Publised</h1>";
}
else {
while ($row = mysqli_fetch_assoc($select_all_posts_query)) {
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_author = $row['post_author'];
$post_category_id = $row['post_category_id'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'], 0, 100);
?>
<div class="col-sm-12 col-lg-4 col-md-6">
<div class="product-item bg-light">
<div class="card">
<div class="thumb-content">
<!-- <div class="price">$200</div> -->
<a href="post.php?p_id=<?php echo $post_id; ?>">
<img class="card-img-top img-fluid" src="images/<?php echo $post_image; ?>" alt="Card image cap">
</a>
</div>
<div class="card-body">
<h4 class="card-title"><a href=""><?php echo $post_title ?></a></h4>
<ul class="list-inline product-meta">
<li class="list-inline-item">
<a href=""><i class="fa fa-folder-open"></i>
<?php
global $connection;
$query = "SELECT * FROM categories WHERE cat_id={$post_category_id}";
$select_categories_id = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($select_categories_id)) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<td>{$cat_title}</td>";
}
?>
</a>
</li>
<li class="list-inline-item">
<a href=""><i class="fa fa-calendar"></i><?php echo $post_date ?></a>
</li>
</ul>
<p class="card-text"><?php echo $post_content ?></p>
<div class="product-ratings">
<!-- <ul class="list-inline">-->
<!-- <li class="list-inline-item selected"><i class="fa fa-star"></i></li>-->
<!-- <li class="list-inline-item selected"><i class="fa fa-star"></i></li>-->
<!-- <li class="list-inline-item selected"><i class="fa fa-star"></i></li>-->
<!-- <li class="list-inline-item selected"><i class="fa fa-star"></i></li>-->
<!-- <li class="list-inline-item"><i class="fa fa-star"></i></li>-->
<!-- </ul>-->
</div>
</div>
</div>
</div>
</div>
<?php
}
}
}
else{
header("Locations:text_us.php");
}
?>
</div>
</div>
</section>
<?php include "includes/footer.php"?>