OK, here goes the working code with right permissions:
<?php
function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
include_once "YOUR_PATH_TO/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
$tbl = $DBHOST_TBL_PREFIX;
$r = mysql_db_query($DBHOST_DBNAME, "SELECT resource_id
FROM ".$tbl."group_cache
WHERE user_id=0
AND group_cache_opt>>1&1=1", $cid);
$lm='';
while( list($id) = mysql_fetch_row($r) ) $lm .= $id.',';
$lm = substr($lm, 0, -1);
$r = mysql_db_query($DBHOST_DBNAME, "SELECT
".$tbl."msg.id,
".$tbl."msg.subject,
".$tbl."thread.last_post_date,
".$tbl."thread.last_post_id
FROM
".$tbl."thread
INNER JOIN ".$tbl."msg
ON ".$tbl."thread.root_msg_id=".$tbl."msg.id
WHERE
".$tbl."thread.forum_id IN (".$lm.") AND
".$tbl."msg.apr=1
ORDER by
".$tbl."thread.last_post_id DESC
LIMIT ".$n_posts, $cid);
while( $obj = mysql_fetch_object($r) ) {
/* Here you do your actual code, below is a working example */
$tm = date("d/m/Y H:i", $obj->last_post_date);
echo "<p><SPAN CLASS=\"date\">".$tm."</SPAN> -
<a href=\"".$WWW_ROOT."index.php?t=msg&goto=".$obj->id."\">".$obj->subject."</a>
<a href=\"".$WWW_ROOT."index.php?t=tree&goto=".$obj->last_post_id."\">»»</a></p>\n";
}
mysql_free_result($r);
}
?>
Put this in your file apart or in the place you need.
Then make a call for it:
<?php
fetch_forum_posts(10);
?>
Done
*Phew*
[Updated on: Fri, 22 October 2004 23:23]
Report message to a moderator