Welcome to Geeklog, Anonymous Tuesday, April 16 2024 @ 12:29 am EDT

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"Wink or die ("Could not connect to MySQL"Wink; mysql_select_db("$db"Wink or die("Could not select database"Wink; $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. Smile
 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
 Quote

Anonymous

Anonymous
That's a great idea. Thanks.
 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.
 Quote

All times are EDT. The time is now 12:29 am.

  • 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