How to get the last 5 topics from a miniBB table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thew
    New Member
    • Aug 2010
    • 69

    How to get the last 5 topics from a miniBB table?

    Code:
    <?php
    							$getsql = mysql_query("SELECT * FROM minibbtable_topics ORDER BY topic_id DESC LIMIT 5");
    							if($getsql){
    								if(mysql_num_rows($sql) == 0){
    									echo 'No recent topics';
    								}
    								else
    								{
    									while($getdata = mysql_fetch_assoc($sql)){
    										echo '<a href="forum/index.php?action=vthread&topic='. $getdata['topic_id'] .'">'. text_chop($getdata['topic_title'], 50) .'</a>';
    									}
    								}
    							}
    							else
    							{
    								trigger_error(mysql_error());
    							}
    						?>


    Help please,

    im trying to get the last 5 topics from a miniBB table. Now, it won't work. It just gives back totally nothing.. Can you guys help me?

    Thew
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    What is in the variable $sql?

    Two things I'm thinking here.

    a) The first if block is failing and there is no mysql_errors.

    b) The second if block is failing because of $sql and never enters the while loop either.

    Comment

    • Thew
      New Member
      • Aug 2010
      • 69

      #3
      I fixed it, the script im using is so big (876 rows and not finished) that i need to use multiple variables... So i got confused what $getsql and $sql was... But still thanks.

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        In bigger projects I would recommend using more descriptive variables to help you avoid those problems. Something like $topic_sql.

        Comment

        Working...