-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtopic.php
More file actions
103 lines (91 loc) · 2.78 KB
/
Copy pathtopic.php
File metadata and controls
103 lines (91 loc) · 2.78 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
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
<?php
//topic.php
include 'connect.php';
include 'header.php';
//first select the topic based on $_GET['topic_id']
$sql = "SELECT
topic_id,
topic_subject
FROM
topics
WHERE
topics.topic_id = " . mysqli_real_escape_string($conn, $_GET['id']);
$result = mysqli_query($conn, $sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.' . mysqli_error($conn);
}
else
{
if(mysqli_num_rows($result) == 0)
{
echo 'This topic does not exist.';
}
else
{
//display category data
while($row = mysqli_fetch_assoc($result))
{
echo '<h2>Posts in ' . $row['topic_subject'] . ' topic</h2>';
$topic_id = $row['topic_id'];
}
//do a query for the posts
$sql = "SELECT
posts.post_id,
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_topic = " . mysqli_real_escape_string($conn, $_GET['id']);
$result = mysqli_query($conn, $sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysqli_num_rows($result) == 0)
{
echo 'This topic is empty.';
}
else
{
//prepare the table
echo '<table border="1" style="margin-bottom: 20px">
<tr>
<th>Post</th>
<th>Date and user name</th>
</tr>';
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td class="leftpart">';
echo $row['post_content'];
echo '</td>';
echo '<td class="rightpart">';
echo date('d-m-Y', strtotime($row['post_date']));
echo "\n";
echo $_SESSION['user_name'];
echo '</td>';
echo '</tr>';
}
echo '</table>';
echo '<form method="post" action="reply.php?id=' . $topic_id . '">
<textarea name="replyContent"></textarea>
<input type="submit" value="Submit reply" />
</form>';
}
}
}
}
include 'footer.php';
?>