Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 08:37 pm EST
Geeklog Forums
Top 10 Forum Posts
Status: offline
3mta3
Forum User
Newbie
Registered: 01/06/03
Posts: 4
Here's a little something I used to get the 10 latest posts from a phpBB2 forum and display the topics in a bulleted list. Each list item is a link to the post.
Here's the code:function phpblock_RecentPosts()
{
$link = mysql_connect("$host", "$user", "$pass" or die ("Could not connect to MySQL"
mysql_select_db("$db" or die("Could not select database"
$sql = "SELECT * from phpbb_topics WHERE forum_id=1 ORDER BY `topic_id` ASC LIMIT 0, 10";
$result = mysql_query($sql);
while ($row = mysql_fetch_object($result)) {
$topic = $row->topic_title;
$url .= "<li><a href="/forum/viewtopic.php?t=$row->topic_id">$topic</a></li>";
}
return($url);
mysql_free_result($result);
}
Of course you'll have to fill in YOUR values for $host, $user, $pass, and $db
You'll also need to set forum_id to something other than "1" if you want to pull from a different forum.
You can see my working example at http://teamkarn.net
The block is on the right and titled "Recent Forum Posts"
Enjoy.
11
12
Quote
Status: offline
Dirk
Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
If your forum tables are in the same database as Geeklog's tables, you could use Geeklog's database config variables ($_DB_user, etc.), so you don't have to enter all that data in the block again. Or, better yet, use Geeklog's DB_query() etc. functions, so you don't even have to do the mysql_connect().
Of course that is not an option if you have Geeklog and the forum in two separate databases.
bye, Dirk
10
10
Quote
Anonymous
Anonymous
That's a great idea. Thanks.
8
9
Quote
Status: offline
3mta3
Forum User
Newbie
Registered: 01/06/03
Posts: 4
Here's the revised code per Dirk's suggestion. It works perfectly on my site.
function phpblock_RecentPosts()
{
$sql = "SELECT * from phpbb_topics WHERE forum_id=1 ORDER BY `topic_id` ASC LIMIT 0, 10";
$result = DB_query($sql);
while ($row = mysql_fetch_object($result)) {
$topic = $row->topic_title;
$url .= "<li><a href="/forum/viewtopic.php?t=$row->topic_id">$topic</a></li>";
}
return($url);
mysql_free_result($result);
}
Thanks Dirk.
26
10
Quote
All times are EST. The time is now 08:37 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content