Script 17.4 Forum Main Page

Output
Emne: Lagt til av: Lagt ut på: Svar: Siste svar:
Byttet til PHP 5.0 fra PHP 4.0 - variabler utilgjengelige troutster 29-Oct-11 10:26 AM 4 30-Oct-11 6:16 AM
Automatisk bildekontroll Ute 29-Oct-11 10:45 PM 0 29-Oct-11 10:45 PM
Source
<?php # Script 17.4 - forum This page lists the threads in a forum.
include (CHAPTER_PATH.'/'.$chapter.'/includes/17.1.php');

// Retrieve all the messages in this forum...

// If the user is logged in and has chosen a time zone, use that to convert the dates and times:
if (isset($_SESSION['tz'])) {
	$first = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['tz']}')";
	$last = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['tz']}')";
} else {
	$first = 'p.posted_on';
	$last = 'p.posted_on';
}

// The query for retrieving all the threads in this forum, along with the original user, when the thread was first posted, when it was last replied to, and how many replies it's had
$q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM mb_threads AS t INNER JOIN mb_posts AS p USING (thread_id) INNER JOIN mb_users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
$r = mysqli_query($link, $q);
if (mysqli_num_rows($r) > 0) {

	// Create a table:
	echo '<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
		<tr>
			<td align="left" width="50%"><em>' . $words['subject'] . '</em>:</td>
			<td align="left" width="20%"><em>' . $words['posted_by'] . '</em>:</td>
			<td align="center" width="10%"><em>' . $words['posted_on'] . '</em>:</td>
			<td align="center" width="10%"><em>' . $words['replies'] . '</em>:</td>
			<td align="center" width="10%"><em>' . $words['latest_reply'] . '</em>:</td>
		</tr>';

	// Fetch each thread:
	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

		echo '<tr>
				<td align="left"><a href="index.php?chapter=17&amp;script=17.5&amp;tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td>
				<td align="left">' . $row['username'] . '</td>
				<td align="center">' . $row['first'] . '</td>
				<td align="center">' . $row['responses'] . '</td>
				<td align="center">' . $row['last'] . '</td>
			</tr>';

	}
	
	echo '</table>'; // Complete the table.
	
} else {
	echo '<p>' . $words['no_messages'] . '</p>';
}

// Include the footer file:
include (CHAPTER_PATH.'/'.$chapter.'/includes/17.2.php');
?>