1 (edited by volomike 2008-09-27 15:00)

Topic: Last Forum Posts

I need to build a screen widget on my site that will show the last 10 forum posts. The columns I need are:

* thread topic (with hyperlink to jump right to it)
* last poster's username and date/time
* # of replies on that thread topic
* # of views on that thread topic
* forum name (with hyperlink to jump right to it)

I think I can figure out how to do this the SQL way, but is there like a way I can do it by calling a function already in the forum system? For instance, I'm already loading common.php like so:

define('FORUM_ROOT','forums/');
require_once('forums/config.php');
require_once('forums/include/common.php');
ini_set('error_reporting',6135);

EDIT: Oh, I forgot to mention -- I'm loading this screen widget/gadget on a page separate from my website -- one directory above it "forums".

Re: Last Forum Posts

SELECT
    `p`.`topic_id`,
    `t`.`subject`,
    `p`.`poster`,
    `p`.`posted`,
    `t`.`num_replies`,
    `t`.`num_views`,
    `t`.`forum_id`,
    `f`.`forum_name`
FROM
    `pun_posts` AS `p` 
JOIN
    `pun_topics` AS `t` 
ON
    `p`.`topic_id` = `t`.`id` 
JOIN
    `pun_forums` AS `f`
ON
    `t`.`forum_id` = `f`.`id`
GROUP BY 
    `t`.`id`
ORDER BY
    `p`.`posted` DESC 
LIMIT 10;