Is there a way to inlude a post in a phpBB forum and include it into a html document to be used as a news post?
bump
Couldn’t I also read it directly form the database?
Or even the opposite and jus add the include string into both my new page and the forum?
I don’t really use phpBB, so I’m not sure if there’s a method to do this already available. If I needed to do this I’d probably just create a PHP function that would allow me to connect right to the phpBB database, pull the post I needed and then output it.
I assume phpBB uses a unique ID for each post. So in your function pass the id of the post you want to use. Then:
-
Connect to the phpBB database (if you’re not already)
-
Use the ID passed to the function in your SQL statement to get the post
-
Format the post (optional) - if it’s too long, truncate it - add a link to the post at your phpBB board - etc.
-
Close the database connection
-
Echo out the code - or return it if you’d rather do that
Then you have a function that you can use over and over again incase you want to do more than just add one post to your site.
Heres some code feel free to edit and use however you want
To use: paste code wherever you want the news displayed, and fix configuration(First Part) to work for your server.
<?php
//A simple news script to read news from phpBB forums
//Config
$user = "SET ME";//The MYSQL username
$pass = "SET ME";//The MYSQL password
$ft = "News";//What the forum name is
$db = "SET ME";//Database name
$count = 3;//Number of news to show
$template "<h3><--TITLE--></h3><br><--BODY-->";//What is printed <--TITLE--> is replaced with title <--BODY--> is replaced with post
?>
<?php
mysql_connect(localhost,$user,$pass) or die('Could not connect');
@mysql_select_db($db) or die( "Unable to select database");
$query = 'SELECT * FROM `phpbb_forums` WHERE `forum_name`="'.$ft.'"';
$res = mysql_query($query);
$fid = mysql_result($res, 0, "forum_id");
$query = 'SELECT * FROM `phpbb_topics` WHERE `forum_id`="'.$fid.'"';
$rest = mysql_query($query);
$pid = mysql_result($rest, 0, "topic_first_post_id");
$query = 'SELECT * FROM `phpbb_posts_text` WHERE `post_id`="'.$pid.'"';
$resp = mysql_query($query);
for($i=0;$i<$count;$i++) {
if(mysql_result($resp, $i, "post_id")) {
$temp = $template;
$temp = str_replace("<--TITLE-->",mysql_result($rest, $i, "topic_title"),$temp);
$temp = str_replace("<--BODY-->",mysql_result($resp, $i, "post_text"),$temp);
echo $temp;
}
}
?>
Yeah what they said works great. You can set your sql statement to display all posts in a certain thread. That way whenever you post in that thread it will show up on your main page news.