Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/9458-trying-to-get-last-posttopic-from-forum/
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]
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*
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.