Forum Moderators: coopster

Message Too Old, No Replies

Pulling Recent Forum Posts From Outside Site

php and discussion forums phpBB

         

lexa1999

1:34 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



I am using PHPbb to host a discussion forum on one site. On another site, I would like to feature the last five posts made to the discussion forum. In other words, pull the most recent posts and display them on this "outside" site. I have some code to pull and display posts from a forum living on the same URL. Anybody know how I modify it so that I can display posts on an outside site?
--------------------------
<?

$absolutPath = "/absolut/path/to/config.php";
$urlPath = "http://www.domain.de/folder";
$limit = "10";

include_once("$absolutPath");
$db = @mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Problem!?");
@mysql_select_db("$dbname",$db) or die("No available?");

$sql = "SELECT t.topic_title, t.topic_time, u.username, t.topic_id, f.forum_id
FROM topics t, forums f, users u WHERE t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND f.forum_type!= '1'
ORDER BY topic_time DESC LIMIT $limit";

if ($r = mysql_query($sql, $db)) {
echo "<table width=\"50%\">";
echo "<tr><td><b>Recent Topics:</b></td></tr>";
while($m = mysql_fetch_array($r)) {
$j = stripslashes($m[topic_title]);
if ($shortsubj) $k = substr($j, 0, 20) . "..."; else $k = $j;
echo "<tr><td><a href=\"$urlPath/viewtopic.php?topic=$m[topic_id]&forum=$m[forum_id]\">$k</a></td>";
echo "<td> ( ".$m["topic_time"]." )</td>";
echo "<td> by ".$m["username"]."</td></tr>";
}
echo "</table>";
}

?>

barn_de

2:23 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Hi lexa1999,

obviously you have to connect to the mysql db where phpbb is running. so $dbhost is something like domain-with-phpbb-running.com.

you also have to open up the mysql db. you have to allow connections from outside.

if this is not set up yet, there are 2 things you should check.

1. my.cnf (mysql config file)
in the my.cnf the following lines should open up the connection from outside:

port = 3306
#skip-networking (the # is there on purpose)

2. permissions of the db user.
the user you want to use to connect with the mysql db has to have the right host set up. (user table in the mysql db)

hope this helps

barn

lexa1999

2:48 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Hi Barn,

Thanks for your help.

Another question- Do I get rid of the $absolutpath variable all together? From the error message I"m getting, it looks like PHP is looking for the include file on the server that is displaying the posts (not the server that is hosting the forum).

Error:

Warning: main(/forumtemp/webroot/htdocs/config.php): failed to open stream: No such file or directory in /home/website/www/services/test.php on line 63

Thanks.

lexa1999

1:44 pm on Apr 6, 2004 (gmt 0)

10+ Year Member



Ok, just to follow up on this:

What I did was to create a page on the site that was running the forum and the database from which I wanted to pull the posts. That page pulls and displays the 10 most recent posts. Then on my other site I just did an include of this page. Much easier than trying to connect to an external database.

dvduval

1:47 pm on Apr 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Topics Anywhere does that quite nicely:
[afsvlaanderen.be...]

lexa1999

2:10 pm on Apr 6, 2004 (gmt 0)

10+ Year Member



Yeah, just checked that out. That is pretty cool.