Jump to content


Photo

Trying to get last post/topic from forum


  • Please log in to reply
2 replies to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 10 May 2006 - 09:08 AM

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!
    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";
    }

PHP is my friend (=

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 May 2006 - 10:37 AM



Somethink like that.
    
$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());


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 10 May 2006 - 03:33 PM

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*
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users