Repository navigation
Expand file tree
/
Copy pathsearch_users_ajax.php
More file actions
71 lines (59 loc) · 2.3 KB
/
Copy pathsearch_users_ajax.php
File metadata and controls
71 lines (59 loc) · 2.3 KB
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
<!--Bootstrap Link-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- CSS Stylesheet -->
<link rel="stylesheet" href="CSS/search_users.css">
<?php
/**
* DISPLAY DATA FROM THE DATABASE ASYNCHRONOUSLY ON THE SEARCH_USERS.PHP PAGE.
*
* @version PHP 8.0.12
* @since July 2022
* @author AtharvaShah
*/
session_start();
require "connection.php";
require "functions.php";
$user_data = check_login($con);
$username = $user_data['user_name'];
if (isset($_POST['search'])) {
$name = mysqli_real_escape_string($con,$_POST['search']);
//filter out logged in users username.
$query = "SELECT `user_name`, `profile_pic` FROM `users` WHERE `user_name` LIKE '%$name%' and `user_name`!='$username' LIMIT 5";
$exec = mysqli_query($con, $query);
if(mysqli_num_rows($exec) > 0){
while ($result = mysqli_fetch_assoc($exec)) {
?>
<center>
<!-- <div class='search-results'> -->
<div id="list">
<!-- Assigning searched result in "Search box" in "search.php" file. -->
<?php
if ($result["user_name"]) {
?>
<a class="my-list-item" href=profile.php?user_name=<?php echo $result['user_name'] ?>>
<div class="list-item__avatar">
<img src="<?php echo $result['profile_pic'] ?>">
</div>
<div class="list-item__content">
<strong class="list-item__name">
<?php echo $result['user_name'] ?></strong>
</div>
</a>
<?php
}
?>
</div>
<!-- </div> -->
</center>
<!-- Below php code is just for closing parenthesis. Don't be confused. -->
<?php
}}else{
echo "<div class='no-res'>No Results Found</div>";
}
}
mysqli_close($con);
?>
</ul>
<!-------------------------------------------------------------------------------------
NO HTML OR JAVASCRIPT IS REQUIRED FOR THIS PAGE
------------------------------------------------------------------------------------->