-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetchFollowList.php~
49 lines (43 loc) · 1.71 KB
/
fetchFollowList.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
<?php
session_start();
include 'mylib.php'; // Include your database connection file
db_connect(); // Establish the database connection
global $db;
$userID = intval($_GET['userID']); // The ID of the profile being viewed
$type = $_GET['type']; // "followers" or "following"
if ($type === 'followers') {
// Query to get followers of the user
$sql = "SELECT users.UserID, users.displayName, users.profilePicture
FROM FollowingConnections
JOIN users ON FollowingConnections.UserID = users.UserID
WHERE FollowingConnections.FollowingID = ?";
} else {
// Query to get users that the user is following
$sql = "SELECT users.UserID, users.displayName, users.profilePicture
FROM FollowingConnections
JOIN users ON FollowingConnections.FollowingID = users.UserID
WHERE FollowingConnections.UserID = ?";
}
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $userID);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<ul>";
while ($row = $result->fetch_assoc()) {
$profileLink = "userProfile.php?displayName=" . urlencode($row['displayName']);
$profilePicture = !empty($row['profilePicture']) ? htmlspecialchars($row['profilePicture']) : 'default-profile.png';
// Display each user as a clickable link
echo "<li>";
echo "<a href='" . $profileLink . "'>";
echo "<img src='" . $profilePicture . "' alt='Profile Picture' style='width:30px; height:30px; border-radius:50%; margin-right:10px;'>";
echo htmlspecialchars($row['displayName']);
echo "</a>";
echo "</li>";
}
echo "</ul>";
} else {
echo "<p>No users found.</p>";
}
$stmt->close();
?>