[ Tutorial : PHP ] New posts on external page - phpBB

User avatar
Site Admin
Posts: 24
Joined: Tue Jul 20, 2010 10:31 pm
Location: Rochester, NY
PostPosted: Fri Jul 23, 2010 10:13 pm
This snippet will allow you to show the newest posts from your forum on any other website you add it to.
You can view a working example at the top of (login to view link)

Code: (login to view link)
<?php
// Setup our variables array
$new_posts = array();
$new_posts['BASELINK']      = 'http://yourforums.com'; // Base link to your phpBB forums website without trailing slash
$new_posts['POSTDB']         = 'your_database'; // Database name
$new_posts['POSTTBL']         = 'phpbb_posts'; // Posts table name, incase you changed it from it's default
$new_posts['USERTBL']         = 'phpbb_users'; // Users table name, incase you changed it from it's default
$new_posts['FORUMTBL']      = 'phpbb_forums'; // Forums table name, incase you changed it from it's default
$new_posts['POSTLIMIT']      = '2'; // How many posts to fetch and show

// Fetch the newest forum posts
$grabForumPosts = mysql_query("SELECT * FROM ".$new_posts['POSTDB'].".".$new_posts['POSTTBL']." ORDER BY post_id DESC LIMIT ".$new_posts['POSTLIMIT']."");
while($fetchPosts = mysql_fetch_object($grabForumPosts)) {
   $postID       = $fetchPosts->post_id;
   $postT_ID       = $fetchPosts->topic_id;
   $postF_ID      = $fetchPosts->forum_id;
   $postU_ID      = $fetchPosts->poster_id;
   $postTime      = date('Y-m-d H:i:s', $fetchPosts->post_time);
   $postSubject   = $fetchPosts->post_subject;
   
   // Grab the members name
   $grabUsername = mysql_query("SELECT username FROM ".$new_posts['POSTDB'].".".$new_posts['USERTBL']." WHERE user_id = '$postU_ID'");
   $fetchUser = mysql_fetch_object($grabUsername);
   $postUser = $fetchUser->username;
   
   // Grab the Forum Name
   $findForumName = mysql_query("SELECT forum_name FROM ".$new_posts['POSTDB'].".".$new_posts['FORUMTBL']." WHERE forum_id = '$postF_ID'");
   $fetchForum = mysql_fetch_object($findForumName);
   $postForum = $fetchForum->forum_name;
   
   // Put together our content
   $postContent   = 'In: '.$postForum.'<br />By: '.$postUser;
   echo '<p><a href="'.$new_posts['BASELINK'].'/viewtopic.php?f='.$postF_ID.'&t='.$postT_ID.'">'.$postSubject.'</a><br />'.$postContent.'</p>';
}
?>

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest