-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.php
81 lines (65 loc) · 1.8 KB
/
index2.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
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
<!-- External stylesheet -->
<link rel="stylesheet" type="text/css" href="style.css">
<?php
// Start the session
require_once('startsession.php');
// Insert the page header
$page_title = 'FriendTopic';
require_once('header.php');
// Constants:
require_once('appvars.php');
// Database connection variables:
require_once('dbconnect.php');
// Show the navigation menu
require_once('navmenu.php');
// Auto logout after 5min:
//require_once('autologout.php')
// Connect to the database
$dbc = db_connect();
// Set the encoding...
mysqli_set_charset($dbc, 'utf8');
// Create query to get topic names and users in each topic:
$query =
"SELECT mismatch_topic.name, mismatch_user_topic.topic_id, COUNT(*)
FROM mismatch_user_topic
INNER JOIN mismatch_topic
ON mismatch_user_topic.topic_id = mismatch_topic.topic_id
GROUP BY mismatch_user_topic.topic_id
ORDER BY COUNT(*) DESC";
// Query database passing query to function in dbconnect.php:
$data = mysqli_query($dbc, $query);
?>
<div class="TenPxPaddingDiv jumbotron">
<h1>Topics</h1>
<table>
<?php
while($row = mysqli_fetch_array($data)){
// If user is logged in, display link:
if(isset($_SESSION['user_id'])){
?>
<tr>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php
echo '<a href="viewtopics.php?topic_id=' . $row['topic_id'] . '&name=' . $row['name'] . '">' . "(" . $row['COUNT(*)'] . ")" . "</a>";
?>
</td></tr>
<?php
}
// If user is not logged in, just display topic w/ no link:
else{
?>
<tr><td><?php echo $row['name']; ?></td><td><?php echo "(" . $row["COUNT(*)"] . ")"; ?></td></tr>
<?php
}
}
?>
</table>
</div>
<?php
mysqli_close($dbc);
// Insert the page footer
require_once('footer.php');
?>