FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Looking for hack...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Newest Posts with date and name ? Re: Looking for hack... [message #12061 is a reply to message #11584] Sun, 27 July 2003 13:37 Go to previous messageGo to previous message
Wild_Cat is currently offline  Wild_Cat   Ukraine
Messages: 144
Registered: November 2002
Location: Odessa, Ukraine
Karma:
Senior Member
Well, I needed the dates too, so, although I'm by far not a PHP pro, I optimised the code given by protoss to a template-like result: you don't have to watch your server_name/db_name/username/password/MySQL table prefixes any more - it takes it all from your GLOBALS.php
(it also pointed out to msg.php in the root dir which doesn't exist in version 2.5.0 which I use and for which this code is done consequently)
and I managed to add the date to the code, it turned out to be indeed easy enough. Well, it took me more than a couple of minutes, since I'm not an SQL pro either but I needed it myself, so... here you are:

function fetch_forum_posts($n_posts) /* n_posts is the number of messages you wish to fetch */
{
        include_once "forum/fud/include/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 p_READ='Y'", $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.approved='Y'
                                        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 $tm." - <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."\">&raquo;&raquo;&raquo;</a><br>\n";
        }
        mysql_free_result($r);
}


So then you only have to call on that function, indicating as parameter the number of posts you want to fetch. For changing the date-time format in the date() function - see the PHP help file.

Here is the working example (theme names in Russian but it's not essential) http://avalon.net.ua/forum.php calling fetch_forum_posts(5);

I have updated the script for myself with another feature and do so for you. Now you have two links:
1) [/u]thread root message subject[/u] - linking to the beginning of the theme in flat view;
2) [/u]>>>>>>[/u] - linking to the last message of the thread in tree view
(you may vary them at will/need)


Lady of Avalon

[Updated on: Fri, 02 January 2004 03:54]

Report message to a moderator

[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon9.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon9.gif
Read Message
Read Message
Read Message
Read Message
Previous Topic: New threads on the front page of the site
Next Topic: General Hacking Recommendation please
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 22:54:48 GMT 2024

Total time taken to generate the page: 0.04172 seconds