-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.php
123 lines (100 loc) · 5.81 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
<?php require_once("include/DB.php"); ?>
<?php require_once("include/Sessions.php"); ?>
<?php require_once("include/Functions.php"); ?>
<?php
global $ConnectingDB;
if (isset($_POST["Category"]) && $_POST["Category"]!="all"){
echo 'Category: <button style=" background-image: linear-gradient(to right top, #2ec771, #4dd163, #6bdb51, #89e33a); padding:8px; border-radius:20px; color:white; border:none; margin-bottom:10px"><b>'.$_POST['Category'].'</b></button>';
$Category = $_POST["Category"];
$ViewQuery = "SELECT * FROM admin_panel WHERE category='$Category' ORDER BY id desc";
}
elseif(isset($_POST["Search"]) && $_POST["Search"]!="everything"){
echo 'Search for: <button style=" background-image: linear-gradient(to right top, #2ec771, #4dd163, #6bdb51, #89e33a); padding:8px; border-radius:20px; color:white; border:none; margin-bottom:10px"><b>'.$_POST['Search'].'</b></button>';
$Search = $_POST["Search"];
$ViewQuery = "SELECT * FROM admin_panel
WHERE datetime LIKE '%$Search%'
OR title LIKE '%$Search%'
OR category LIKE '%$Search%'
OR post LIKE '%$Search%'
OR author LIKE '%$Search%'
ORDER BY id desc";
} elseif(isset($_POST["Page"])) {
// echo 'IN Page';
//Pagination
$Page = $_POST["Page"];
$PostsLimit = 5;
if($Page==0 || $Page<1){
$ShowPostFrom = 0;
} else {
$ShowPostFrom = ($Page*$PostsLimit)-$PostsLimit;
}
$ViewQuery = "SELECT * FROM admin_panel ORDER BY id desc LIMIT $ShowPostFrom, $PostsLimit";
} elseif($_POST["Search"]="everything" || $_POST["Category"]="all") {
echo 'Categories: <button style=" background-image: linear-gradient(to right top, #2ec771, #4dd163, #6bdb51, #89e33a, #a8eb12); padding:8px; border-radius:14px; color:white; border:none; margin-bottom:10px"><b>All</b></button>';
//Default
$ViewQuery = "SELECT * FROM admin_panel ORDER BY id desc";
$CountQuery = "SELECT COUNT(*) FROM admin_panel ORDER BY id desc";
}
$Execute = $Connection->query($ViewQuery);
if(mysqli_num_rows($Execute)>0){
// echo mysqli_num_rows($Execute);
while($DataRows = $Execute->fetch_assoc()){
$PostId = $DataRows["id"];
$DateTime = $DataRows["datetime"];
$Title = $DataRows["title"];
$Category = $DataRows["category"];
$Admin = $DataRows["author"];
$Image = $DataRows["image"];
$Post = $DataRows["post"];
if(strlen($DateTime)>11){$DateTime = substr($DateTime,0,11);}
if(strlen($Title)>28){$Title = substr($Title,0,28).'..' ;}
echo '
<div class="post-container">
<img src="./uploads/'.$Image.'" alt="">
<div class="post-text">
<div class="first-line">
<h3 class="post-title"><a href="FullPost.php?id='.$PostId.'">'.$Title.'</a></h3>
<p class="read-time">'.$DateTime.'</p>
</div>
<div class="second-line">
<p class="post-descp">';
if(strlen($Post)>400){$Post = substr($Post,0,400);}
echo $Post;
$ConnectingDB;
// $UserId = $_SESSION["User_Id"];
$CheckClapQuery = "SELECT COUNT(*) FROM claps
WHERE admin_panel_id='$PostId' ";
$ExecuteClapQuery = $Connection->query($CheckClapQuery);
// $ClapsCount = $ExecuteClapQuery->fetch_assoc();
$TotalClaps = $ExecuteClapQuery->fetch_assoc()['COUNT(*)'];
echo '</p>
</div>
<div class="third-line">
<img src="https://img.icons8.com/ios/25/000000/applause.png" alt=""> ';
if($TotalClaps){
echo ' '.$TotalClaps;
}
else{
echo ' 0';
}
$ConnectingDB;
$QueryApproved = "SELECT COUNT(*) from comments WHERE admin_panel_id='$PostId' AND status='ON' ";
$ExecuteApproved = $Connection->query($QueryApproved);
$RowsApproved = $ExecuteApproved->fetch_assoc();
$TotalApproved = array_shift($RowsApproved);
if($TotalApproved){
echo ' | Comments: '.$TotalApproved;
}
else{
echo ' | Comments: 0';
}
echo'
</div>
</div>
</div>
';
}
} else {
echo "No Matching Results";
}
?>