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
|
<?php
include_once 'header.php';
?>
<section>
<h2>Welcome to the cflip.net forum!</h2>
Latest Updates:
<ul>
<li>5 latest threads are displayed on the homepage</li>
</ul>
</section>
<table>
<tr>
<th class="left">Category</th>
<th class="right">Latest Thread</th>
</tr>
<?php
include_once 'includes/db_inc.php';
$sql = "SELECT cat_id, cat_name, cat_description FROM categories";
$result = mysqli_query($dbc, $sql);
if (!$result) {
die('Failure trying to display categories: ' . mysqli_error($dbc));
}
$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads JOIN users ON thread_author = user_id WHERE thread_cat = ? ORDER BY thread_id DESC LIMIT 1";
$stmt = mysqli_stmt_init($dbc);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die('Could not create thread due to internal error: ' . mysqli_error($dbc));
}
while ($row = mysqli_fetch_assoc($result)) {
mysqli_stmt_bind_param($stmt, "i", $row['cat_id']);
mysqli_stmt_execute($stmt);
$thread_res = mysqli_stmt_get_result($stmt);
$thread = mysqli_fetch_assoc($thread_res);
echo '<tr><td class="left">';
echo '<h4><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></h4>';
echo $row['cat_description'];
if ($thread) {
echo '</td><td class="right">' . $thread['thread_subject'] . '<br>';
echo '<small>by <b><a href="user.php?id=' . $thread['user_id'] . '">' . $thread['user_name'] . '</a></b></small></td></tr>';
} else {
$no_threads_msg = 'There are no threads in this category yet.';
echo '</td><td class="right"><small>'. $no_threads_msg .'</small></td>';
}
}
mysqli_stmt_close($stmt);
mysqli_free_result($result);
?>
</table>
<table>
<tr>
<th class="left">Latest Threads <a href="all.php">View All</a></th>
<th class="right">Latest Post</th>
</tr>
<?php
include_once 'includes/db_inc.php';
include_once 'includes/functions_inc.php';
$sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name, cat_id, cat_name FROM threads JOIN users ON thread_author = user_id JOIN categories ON thread_cat = cat_id ORDER BY thread_id DESC LIMIT 5";
$result = mysqli_query($dbc, $sql);
if (!$result) {
die('Error trying to display threads: ' . mysqli_error($dbc));
}
display_threads($dbc, $result, true);
mysqli_free_result($result);
?>
</table>
<?php include_once 'footer.php';?>
|