-
Notifications
You must be signed in to change notification settings - Fork 2
/
search_users.php
218 lines (167 loc) · 7.97 KB
/
search_users.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
<?php
/**
* USERS CAN SEARCH FOR OTHER USERS BY USERNAME AND VISIT THEIR PROFILE.
*
* @version PHP 8.0.12
* @since May 2022
* @author AtharvaShah
*/
session_start();
if (empty($_SESSION)) {
header("Location: login.php");
}
require "header.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Search users, see top followed and most active users" />
<meta name="keywords" content="WYDRN, search users" />
<title> WYDRN - Search Users</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<link rel="icon" type="image/png" href="images/website/favicons/favicon-32x32.png" sizes="32x32">
<link rel="apple-touch-icon" href="images/website/favicons/apple-touch-icon.png">
<link rel="stylesheet" href="CSS/search_users.css">
<!--JQUERY-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<!--title-->
<div class="heading">
<h1><img src="images/Icons/PageHeadings/search.png" class='header-icon'> Search Users<span>Find friendlies with the best tastes.</span></h1>
</div>
<!----------------------------
FLEX COLUMNS
------------------------------->
<div class="columns">
<!----------------------------
Top 10 Most Followed users
------------------------------->
<div class="column" id="most-followed-div">
<article class="leaderboard column">
<header>
<?php echo file_get_contents("images/icons/trophy.svg"); ?>
<h1 class="leaderboard__title"><span class="leaderboard__title--top">WYDRN</span>
<span class="leaderboard__title--bottom">Most Followed Users</span>
</h1>
</header>
</article>
<main class="leaderboard__profiles">
<?php
// Get the top 10 most followed users.
$sql = "SELECT `followed_username` as `user_name`, COUNT(*) as `follower_count` from social GROUP BY `followed_username` ORDER BY `follower_count` desc limit 10";
$query = mysqli_query($con, $sql);
if (mysqli_num_rows($query) > 0) {
for ($i = 1; $i <= mysqli_num_rows($query); $i++) {
$row[$i] = mysqli_fetch_array($query);
$username = $row[$i]['user_name'];
$follower_count = $row[$i]['follower_count'];
?>
<!--HTML CONTENTS-->
<a class="no-und" href=<?php echo "profile.php?user_name=" . $username; ?>>
<article class="leaderboard__profile">
<img src="images/website/assets/numbers/<?php echo $i; ?>.png" alt="" class="leaderboard__picture">
<span class="leaderboard__name"><?php echo $username; ?></span>
<span class="leaderboard__value"><?php echo $follower_count; ?> </span>
</article>
</a>
<?php
}
}
?>
</main>
</div>
<!----------------------------
Search Box
------------------------------->
<div class="column big" id='search-div'>
<center>
<div class="search">
<input type="search" id="search" placeholder="Search for users" autocomplete="off" />
<button class="search__clear"></button>
</div>
<!-- Suggestions will be displayed in below div. -->
<div id="display"></div>
</center>
</div>
<!----------------------------
Top 10 Users with most logged items
------------------------------->
<div class="column" id="most-active-div">
<article class="leaderboard column">
<header>
<?php echo file_get_contents("images/icons/trophy.svg"); ?>
<h1 class="leaderboard__title"><span class="leaderboard__title--top">WYDRN</span><span class="leaderboard__title--bottom">Most Active Users</span></h1>
</header>
</article>
<main class="leaderboard__profiles">
<?php
// Get the top 10 most followed users.
$sql = "SELECT sum(allcount) as media_count, username FROM(
(SELECT username, count(`videogame`) as allcount FROM `data` WHERE videogame!='' GROUP BY username)
UNION ALL
(SELECT username, count(album) AS allcount FROM `data` WHERE album!='' GROUP BY username)
UNION ALL
(SELECT username, count(book) AS allcount FROM `data` WHERE book!='' GROUP BY username)
UNION ALL
(SELECT username, count(movie) AS allcount FROM `data` WHERE movie!='' GROUP BY username)
UNION ALL
(SELECT username, count(tv) AS allcount FROM `data` WHERE tv!='' GROUP BY username)
)t group by username ORDER BY media_count DESC LIMIT 10;";
$query = mysqli_query($con, $sql);
if (mysqli_num_rows($query) > 0) {
for ($i = 1; $i <= mysqli_num_rows($query); $i++) {
$row[$i] = mysqli_fetch_array($query);
// $pfp=$row[$i]['profile_pic'];
$username = $row[$i]['username'];
$media_count = $row[$i]['media_count'];
?>
<a class="no-und" href=<?php echo "profile.php?user_name=" . $username; ?>>
<article class="leaderboard__profile">
<img src="images/website/assets/numbers/<?php echo $i; ?>.png" alt="" class="leaderboard__picture">
<span class="leaderboard__name"><?php echo $username; ?></span>
<span class="leaderboard__value"><?php echo $media_count; ?> </span>
</article>
</a>
<?php
}
}
?>
</main>
</div>
<!-------------------------------------------------------------------------------------
JAVASCRIPT PART
------------------------------------------------------------------------------------->
<script>
//function fill()
function fill(Value) {
$('#search').val(Value);
$('#display').hide();
}
//Jquery for AJAX
$(document).ready(function() {
$("#search").keyup(function() {
var name = $('#search').val();
if (name == "") {
$("#display").html("<div class='no-res'>No Results Found</div>");
} else {
$.ajax({
type: "POST",
url: "search_users_ajax.php",
data: {
search: name
},
success: function(html) {
$("#display").html(html).show();
}
});
}
});
});
</script>
<script src="js/headerResize.js"></script>
</body>
</html>