how to display top 20 posts in a forum

Discussion in 'PHP' started by tldmic, Mar 18, 2010.

  1. #1
    Hallo!!

    thank you all who have been contributing to help me developing my site. I have a problem with my forum. I want it to display only top 20 latest posts, currently what it does, it puts the latest post at the bottom,can anyone out there help me


    <?php

    include "include/constants.php"; //mysql db connection here

    echo "<link rel='stylesheet' href='style.css' type='text/css'>";
    echo "<a href='post.php?user=$session->userid' >


    <div class='newTopic'>New Topic?,Click here</a></div>";
    echo "<table class='maintable' cellspacing=0 >";

    echo "<tr class='headline'>

    <td width=40%>Topic</td>
    <td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";

    $getthreads="SELECT * from forum where parentid='0' order by lastrepliedto DESC";

    $getthreads2=mysql_query($getthreads) or die("Could not get threads");

    while($getthreads3=mysql_fetch_array($getthreads2))

    {

    $getthreads3[title]=strip_tags($getthreads3[title]);

    $getthreads3[author]=strip_tags($getthreads3[author]);

    echo "<tr class='mainrow'>
    <td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td>
    <td>$getthreads3[author]</td>
    <td>$getthreads3[numreplies]</td>
    <td>$getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td>
    </tr>";

    }

    echo "</table>";



    ?>


    many thanks
    tldmic
     
    tldmic, Mar 18, 2010 IP
  2. infotrader

    infotrader Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should display it using query and limit option use query like this

    select * from table limit 0,20 that will fetch only 20 records
     
    infotrader, Mar 18, 2010 IP
  3. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    where should I put that statement in my code above,can you please advice,

    thank you lots

    :)
     
    tldmic, Mar 18, 2010 IP
  4. 99d7737

    99d7737 Active Member

    Messages:
    503
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Which CMS are you using for the forum?
    Almost all of them like vBulletin, IPB, MyBB, SMF has mods which will display the latest posts.
     
    99d7737, Mar 18, 2010 IP
  5. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    you can put it in mysql_query
    
    mysql_query("select * from table limit 0,20 that will fetch only 20 records");
     
    Code (markup):
     
    guardian999, Mar 18, 2010 IP
  6. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you i was able to figure that one out ..... limit 0,20";

    thanks
    but

    what about the posting of the new post to be at the top, how do I go about changing that ?
    I want to display the latest post at the top, can you please advice on that ?
     
    tldmic, Mar 18, 2010 IP