# Include phpBB post into news

**URL:** <https://forum.kirupa.com/t/include-phpbb-post-into-news/186112>\
**Category:** programming\
**Created:** [April 19, 2006, 4:02am UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112 "2006-04-19T04:02:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingofnukes](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kingofnukes](https://forum.kirupa.com/u/kingofnukes)\
**Post date:** [April 19, 2006, 4:02am UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112/1 "2006-04-19T04:02:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kingofnukes](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@kingofnukes](https://forum.kirupa.com/u/kingofnukes)\
**Post date:** [April 20, 2006, 8:41pm UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112/2 "2006-04-20T20:41:56Z")

</div>

_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?

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [April 20, 2006, 9:50pm UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112/3 "2006-04-20T21:50:28Z")

</div>

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:

1. Connect to the phpBB database (if you’re not already)

2. Use the ID passed to the function in your SQL statement to get the post

3. Format the post (optional) - if it’s too long, truncate it - add a link to the post at your phpBB board - etc.

4. Close the database connection

5. 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.

---

<div class="post-metadata">

**Author:** ![signifer123](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@signifer123](https://forum.kirupa.com/u/signifer123)\
**Post date:** [April 20, 2006, 10:47pm UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112/4 "2006-04-20T22:47:24Z")

</div>

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.

```auto

<?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;
}
}
?>

```

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [April 21, 2006, 2:48am UTC](https://forum.kirupa.com/t/include-phpbb-post-into-news/186112/5 "2006-04-21T02:48:39Z")

</div>

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.
