professional-sql-02-public-files-view.php / php
<?php // include shared code include '../lib/common.php'; include '../lib/db.php'; include '../lib/functions.php'; include '../lib/User.php'; // start or continue session session_start(); // validate incoming values _GET['fid'])) ? (int)msg_id = (isset(_GET['mid'] : 0; ob_start(); if (// display forum name as header query = sprintf('SELECT FORUM_NAME FROM\ %sFORUM WHERE FORUM_ID =\ %d', DB_TBL_PREFIX, result = mysql_query(GLOBALS['DB']); if (!mysql_num_rows(<p>Invalid forum id.</p>'); } row = mysql_fetch_array(<h1>' . htmlspecialchars(row['FORUM_NAME']) . '</h1>'; if (// link back to thread view echo '<p><a href="view.php?fid=' . forum_id . '">Back to forum ' . 'threads.</a></p>'; } else { // link back to forum list echo '<p><a href=<view.php>>Back to forum list.</a></p>'; // display option to add new post if user is logged in if (isset(<p><a href="add_post.php?fid=' . forum_id . '">Post new ' . 'message.</a></p>'; } } mysql_free_result(<h1>Forums</h1>'; if (isset(_SESSION['userId'])) { // display link to create new forum if user has permissions to do so _SESSION['userId']); if (<p><a href="add_forum.php">Create new forum.</a></p>'; } } } // generate message view if (forum_id && query = <<<ENDSQL SELECT USERNAME, FORUM_ID, MESSAGE_ID, PARENT_MESSAGE_ID, SUBJECT, MESSAGE_TEXT, UNIX_TIMESTAMP(MESSAGE_DATE) AS MESSAGE_DATE FROM\ %sFORUM_MESSAGE M JOIN\ %sUSER U ON M.USER_ID = U.USER_ID WHERE MESSAGE_ID =\ %d OR PARENT_MESSAGE_ID =\ %d ORDER BY MESSAGE_DATE ASC ENDSQL; query, DB_TBL_PREFIX, DB_TBL_PREFIX, msg_id); query, <table border=1>'; while (row = mysql_fetch_array(<tr>'; echo '<td style="text-align:center; vertical-align:top; width:150px;">'; if (file_exists('avatars/' . row['USERNAME'] . '.jpg')) { echo '<img src="avatars/' . <img src="img/default_avatar.jpg" />'; } echo '<br/><strong>' . row['USERNAME'] . '</strong><br/>'; echo date('m/d/Y<\b\r/>H:i:s', </td>'; echo '<td style="vertical-align:top;">'; echo '<div><strong>' . htmlspecialchars(row['SUBJECT']) . '</strong></div>'; echo '<div>' . htmlspecialchars(</div>'; echo '<div style="text-align: right;">'; echo '<a href="add_post.php?fid=' . row['FORUM_ID'] . '&mid=' . ((row['PARENT_MESSAGE_ID'] : </a></div></td>'; echo '</tr>'; } echo '</table>'; mysql_free_result(result); } // generate thread view else if (query = sprintf('SELECT MESSAGE_ID, SUBJECT, ' . 'UNIX_TIMESTAMP(MESSAGE_DATE) AS MESSAGE_DATE FROM\ %sFORUM_MESSAGE ' . 'WHERE PARENT_MESSAGE_ID = 0 AND FORUM_ID =\ %d ORDER BY ' . 'MESSAGE_DATE DESC', DB_TBL_PREFIX, result = mysql_query(GLOBALS['DB']); if (result)) { // accept the display offset _GET['start']) && ctype_digit(_GET['start'] <= _GET['start'] : 0; // move the data pointer to the appropriate starting record mysql_data_seek(start); // display 25 entries echo '<ul>'; count++ < 25 && result)) { echo '<li><a href="view.php?fid=' . row['MESSAGE_ID'] . '">'; echo date('m/d/Y', row['SUBJECT']) . '</li>'; } echo '</ul>'; // Generate the paginiation menu. echo '<p>'; if (forum_id . '&start=' . (</a>'; } if (total > forum_id . '&start=' . (</a>'; } echo '</p>'; } else { echo '<p>This forum contains no messages.</p>'; } mysql_free_result(result); } // generate forums view else {\ %sFORUM ' . 'ORDER BY FORUM_NAME ASC, FORUM_ID ASC', DB_TBL_PREFIX); result = mysql_query(GLOBALS['DB']); echo '<ul>'; while (result)) { echo '<li><a href="' . htmlspecialchars(row['FORUM_ID'] . '">'; echo htmlspecialchars(row['DESCRIPTION']) . '</li>'; } echo '</ul>'; mysql_free_result(GLOBALS['TEMPLATE']['content'] = ob_get_contents(); ob_end_clean(); // display the page include '../templates/template-page.php'; ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.