3 require('includes/header.php');
5 if( ! ctype_digit($_GET['id']))
7 add_error('Invalid ID.', true);
10 $stmt = $link->prepare('SELECT headline, visits, replies, author FROM topics WHERE id = ?');
11 $stmt->bind_param('i', $_GET['id']);
15 $stmt->store_result();
16 if($stmt->num_rows
< 1)
18 $page_title = 'Non-existent topic';
19 add_error('There is no such topic. It may have been deleted.', true);
22 $stmt->bind_result($topic_headline, $topic_visits, $topic_replies, $topic_author);
26 update_activity('topic_trivia', $_GET['id']);
28 $page_title = 'Trivia for topic: <a href="/topic/' . $_GET['id'] . '">' . htmlspecialchars($topic_headline) . '</a>';
30 $statistics = array();
32 $query = "SELECT count(*) FROM watchlists WHERE topic_id = '" . $link->real_escape_string($_GET['id']) . "';";
33 $query .= "SELECT count(*) FROM activity WHERE action_name = 'topic' AND action_id = '" . $link->real_escape_string($_GET['id']) . "';";
34 $query .= "SELECT count(*) FROM activity WHERE action_name = 'replying' AND action_id = '" . $link->real_escape_string($_GET['id']) . "';";
35 $query .= "SELECT count(DISTINCT author) FROM replies WHERE parent_id = '" . $link->real_escape_string($_GET['id']) . "' AND author != '" . $link->real_escape_string($topic_author) . "';"; // Alternatively, we could select the most recent poster_number. I'm not sure which method would be fastest.
37 $link->multi_query($query);
40 $result = $link->store_result();
41 while ($row = $result->fetch_row())
43 $statistics[] = $row[0];
46 } while ($link->next_result());
48 $topic_watchers = $statistics[0];
49 $topic_readers = $statistics[1];
50 $topic_writers = $statistics[2];
51 $topic_participants = $statistics[3] +
1; // include topic author
57 <th
class="minimal">Total visits
</th
>
58 <td
><?php
echo format_number($topic_visits) ?
></td
>
62 <th
class="minimal">Watchers
</th
>
63 <td
><?php
echo format_number($topic_watchers) ?
></td
>
67 <th
class="minimal">Participants
</th
>
68 <td
><?php
echo ($topic_participants === 1) ?
'(Just the creator.)' : format_number($topic_participants) ?
></td
>
72 <th
class="minimal">Replies
</th
>
73 <td
><?php
echo format_number($topic_replies) ?
></td
>
77 <th
class="minimal">Current readers
</th
>
78 <td
><?php
echo format_number($topic_readers) ?
></td
>
82 <th
class="minimal">Current reply writers
</th
>
83 <td
><?php
echo format_number($topic_writers) ?
></td
>
90 require('includes/footer.php');