Jump to content

Archived

This topic is now archived and is closed to further replies.

Brandon Jaeger

Trying to get last post/topic from forum

Recommended Posts

I'm trying to get the last post/topic from the forum but it's not working too well. Can you tell what I did wrong just by looking at this?

Thanks in advance!
[code]    function get_last_post_by_forum($cid , $fid)
    {
        $query = "SELECT `posterid`, `timestamp` FROM `forum_posts` WHERE `forumid` = '" . $fid . "' ORDER BY `timestamp` DESC LIMIT 1";
        $result = mysql_query($query) or die(mysql_error());

        $row = mysql_fetch_assoc($result);

        $poster_id = $row["posterid"];
        $stamp = $row["timestamp"];

        $time = time_since2($stamp);

        $query = "SELECT `posterid`, `timestamp`, `forumid` FROM `forum_topics` WHERE `catid` = '" . $cid . "' ORDER BY `timestamp` DESC LIMIT 1";
        $result = mysql_query($query) or die(mysql_error());

        $row = mysql_fetch_assoc($result);

        $tpc_stamp = $row["timestamp"];
        $tpc_id = $row["id"];

        if($tpc_id == $fid && $tpc_stamp > $stamp)
        {
            $time = time_since2($row["timestamp"]);
            $poster_id = $row["posterid"];
        }

        if($poster_id > 0)
            return $time . "<br \>by <b>" . name($poster_id , 1) . "</b>";

        return "No posts";
    }[/code]

Share this post


Link to post
Share on other sites


Somethink like that.
[code]    
$query = "SELECT `posterid`, `timestamp`, `forumid` FROM `forum_topics` WHERE `catid` = '" . $cid . "' ORDER BY `timestamp` DESC LIMIT 1 and ORDER BY ASC";
        $result = mysql_query($query) or die(mysql_error());

[/code]

Share this post


Link to post
Share on other sites
That didn't work but I figured it out!

Tip: Don't code when you're tired. Especially a forum! [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

*SOLVED*

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.