Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

returning the last entered value in a mysql table in php

  • 25-04-2005 01:17PM
    #1
    Registered Users, Registered Users 2 Posts: 722 ✭✭✭


    I'm writing a forum, similar to these here pages, all is going well except i want to get the date of the latest post and the poster and insert it into the display topic function. I'm not 100% sure on how to get the latest post but I am trying it using the MAX function in mysql. The code i wrote dont seem to work though. Anyone care to have a look.


    $gettopics = "SELECT * FROM core_forum_topics";
    $execute = mysql_query($gettopics) or die(mysql_error());
    while ($get=mysql_fetch_array($execute))
    {
    $topicid = $get;
    $topictitle = $get;
    $topicdate = $get;
    $topicauthor = $get;


    $countpost = "SELECT count(post_id) FROM core_forum_posts WHERE post_pid = $topicid ORDER BY post_pid DESC";
    $get_count = mysql_query($countpost) or die(mysql_error());
    $number=mysql_result($get_count,0,'count(post_id)');

    $getpost = "SELECT * FROM core_forum_posts WHERE $topicid = MAX(post_pid)";

    $post = mysql_query($getpost) or die(mysql_error());
    while ($getinfo=mysql_fetch_array($post))
    {
    $postauthor = $getinfo;
    $postdate = $getinfo;


    ?>
    do display stuff....

    <?
    }
    }

    any ideas?


Comments

  • Closed Accounts Posts: 36 Caixa


    do an ORDER BY post_pid DESC and extract the first row?


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    uhm are your writing the code for the forum from scratch or are you using a pre-existing one - like vbulletin or phpbb?

    If so the hacks for either of them for what you want to do are already available


  • Registered Users, Registered Users 2 Posts: 722 ✭✭✭stakey


    dont think that will work ciaxa

    what i am trying to do is select the latest post posted under a topic by its ID where the parent ID is equal to the topic ID.

    Ph3n0m --

    I am writing my own forum & CMS from the ground up, my final year project in college


  • Closed Accounts Posts: 36 Caixa


    How about:

    SELECT MAX(post_pid) FROM table WHERE parentID = topicID


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    to make it easier could you post the fields that core_forum_topics contains?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 722 ✭✭✭stakey


    Ph3n0m

    core_forum_topics contains the following fields

    topic_id-- int
    topic_title --varchar
    topic_timestamp --datetime
    topic_author --varchar


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    nevermind, try this :)

    <?
    $countpost = "SELECT * FROM core_forum_posts ORDER BY post_timestamp DESC LIMIT 1";
    $get_count = mysql_query($countpost) or die(mysql_error());
    
    while ($getinfo=mysql_fetch_array($get_count))
    {
    $postid = $getinfo['post_pid'];
    $postauthor = $getinfo['post_author'];
    $postdate = $getinfo['post_timestamp'];
    
    $gettopics = "select *  from core_forum_topics where topic_id = $postid ";
    
    $execute = mysql_query($gettopics) or die(mysql_error());
    while ($get=mysql_fetch_array($execute))
    {
    $topictitle = $get['topic_title'];
    
    
    echo "Topic: $topictitle<br>
    Author: $postauthor<br>
    Date: $postdate
    <P>
    ";
    }
    }
    ?>
    


Advertisement