While looking for some code to insert the latest topics on the homepage, I discovered a load of poor implementations. Here's mine:
- Code: Select all
<h3>from the forum</h3>
<ul>
<?php
$connection = mysql_connect(localhost,'username','password') or die("Service temporarily unavailable"); //use @ before the function to supress errors and remove the die after it for production use
$db = mysql_select_db('databasename',$connection) or die("Service temporairly unavailable");//do the same here
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,4";// i use " where forum_id != 3" as the where clause to exclude topics from the announcements forum
$result = mysql_query($sql);// @ again for production
while ($row = mysql_fetch_array($result))
{
echo '<li><h4><a href="http://forum.minthost.com/viewtopic.php?f='.$row[forum_id].'&t='.$row[topic_id].'">'.$row[topic_title].'</a></h4><p><a href="http://forum.minthost.com/viewtopic.php?f='.$row[forum_id].'&t='.$row[topic_id].'">read more</a></p></li>';
}
?>
</ul>