-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_tweets.php
41 lines (35 loc) · 1.13 KB
/
user_tweets.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
<?php
require_once "config/database.php";
require_once "includes/header.php";
if (!isset($_GET["username"])) {
header("Location: index.php");
exit();
}
$username = $conn->real_escape_string($_GET["username"]);
$sql = "SELECT posts.id, posts.content, posts.created_at, users.username
FROM posts
JOIN users ON posts.user_id = users.id
WHERE users.username = ?
ORDER BY posts.created_at DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
?>
<h2>Tweets by <?php echo htmlspecialchars($username); ?></h2>
<?php if ($result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<div class="tweet">
<p><?php echo nl2br(htmlspecialchars($row["content"])); ?></p>
<p class="tweet-meta">
on <?php echo date(
"Y-m-d H:i",
strtotime($row["created_at"])
); ?>
</p>
</div>
<?php endwhile; ?>
<?php else: ?>
<p>No tweets found for this user.</p>
<?php endif; ?>
<?php require_once "includes/footer.php"; ?>