Topics in extern site (Technics)
Hello,
I would dsiolay the last 5 topics of the forum in extern page.
Do somebody know the html-code?
This could be your HTML-Code:
<div id="new-postings"> <h2>Newest Postings</h2> <ul> <li><a href="/path/to/forum/index.php?id=0000">Subject</a> - Name, 11.12.2010 15:42</li> <li><a href="/path/to/forum/index.php?id=0000">Subject</a> - Name, 11.12.2010 15:40</li> <li><a href="/path/to/forum/index.php?id=0000">Subject</a> - Name, 11.12.2010 15:21</li> <li><a href="/path/to/forum/index.php?id=0000">Subject</a> - Name, 11.12.2010 14:48</li> <li><a href="/path/to/forum/index.php?id=0000">Subject</a> - Name, 11.12.2010 13:72</li> </ul> </div>
But it's not only the HTML source code. You need PHP code too. You have to read the newest postings from the database and generate the output.
// the databese query $Query = "SELECT id, name, subject, UNIX_TIMESTAMP(time) AS time FROM ".$db_settings['forum_table']." ORDER BY time DESC LIMIT 0, 5"; /** * Attention: You'll get the time as it's saved in the database * without respect for timezones settings! * * alternative ways for formatting time string: * DATE_FORMAT(time, 'MySQL-timeformat') AS time * instead UNIX_TIMESTAMP(time) AS time * * description: * with DATE_FORMAT you get a formatted date string out of the database * MySQL-timeformat: see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format * * with UNIX_TIMESTAMP you have to generate the string with PHP later * because you'll get only a unix timestamp (seconds since 01.01.1970 00:00 UTC/GMT) */ // database request $rawResult = mysql_query($Query); // give result of query into an array $result = array(); while ($row = mysql_fetch_assoc($rawResult)) { $result[] = $row; } // generate output $output = '<div id="new-postings">'."\n"; $output .= ' <h2>Newest Postings</h2>'."\n"; if (count($result) > 0) { $output .= ' <ul>'."\n"; foreach ($result as $row) { // only needed if you use UNIX_TIMESTAMP in query, // formatting rules: see http://de3.php.net/manual/en/function.strftime.php $time = strftime("PHP-timeformat",$row['time']); $output .= ' <li><a href="/path/to/forum/index.php?id='.intval($row['id']).'">'.htmlspecialchars($row['subject']).'</a> - '.htmlspecialchars($row['name']).', '.htmlspecialchars($row['time']).'</li>'."\n"; } $output .= ' </ul>'."\n"; } else { $output .= '<p>There are no postings.</p>'."\n"; } $output .= '</div>'."\n"; // put output into HTML somewhere else echo $output;
Tschö, Auge
--
Trenne niemals Müll, denn er hat nur eine Silbe!