-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_posts.php
More file actions
65 lines (55 loc) · 1.69 KB
/
Copy pathfetch_posts.php
File metadata and controls
65 lines (55 loc) · 1.69 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
<?php
// Include the database connection
require 'db.php';
session_start(); // Start session to access the logged-in user's data
$type = $_GET['type'] ?? ''; // Get the type from the query string
// Build the query based on whether a type is provided
$query = 'SELECT * FROM posts';
if ($type) {
$query .= ' WHERE type = ?';
$stmt = $conn->prepare($query);
$stmt->bind_param('s', $type);
} else {
$stmt = $conn->prepare($query);
}
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Posts</title>
<!-- Link to your CSS file -->
<link rel="stylesheet" href="posts.css">
</head>
<body>
<div class="posts">
<?php
while ($row = $result->fetch_assoc()) {
echo '<div class="post">';
echo '<div class="post-left">';
if ($row['image']) {
echo '<img src="uploads/' . htmlspecialchars($row['image']) . '" alt="Post Image" />';
}
echo '</div>';
echo '<div class="post-right">';
echo '<h3>' . htmlspecialchars($row['title']) . '</h3>';
echo '<p>' . htmlspecialchars($row['description']) . '</p>';
echo '<p><strong>Type:</strong> ' . htmlspecialchars($row['type']) . '</p>';
// Only show delete button if the logged-in user is the one who uploaded the post
if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $row['user_id']) {
echo '<a href="delete_post.php?post_id=' . $row['id'] . '" class="btn">Delete</a>';
}
echo '</div>'; // End post-right
echo '</div>'; // End post
}
?>
</div> <!-- End posts -->
<?php
$stmt->close();
$conn->close();
?>
</body>
</html>