Jump to content

[SOLVED] Problem querying last reply for forum


Eiolon

Recommended Posts

Hello,

 

I am making a column called "Last Post" much like the one used on this forum.  It will display the date, time and user of the lastest reply to a thread.  The problem I am having is it's querying the very first reply.

 

Query:

 

// Query the database for topic and reply information.
$query_topics = "SELECT t.*, r.* FROM topics t JOIN replies r ON (t.topic_id = r.reply_topic) WHERE topic_forum = ".$_GET['forum_id']." GROUP BY t.topic_subject ORDER BY t.topic_date DESC";
$topics = mysql_query($query_topics) OR die ('Cannot retrieve a list of topics.');
$row_topics = mysql_fetch_array($topics);

 

PHP:

 

          <table width="100%" border="0" cellspacing="1" cellpadding="6" bgcolor="#CCCCCC">
            <tr bgcolor="#E5E5E5">
              <td><strong>Topic</strong></td>
              <td width="75"><div align="center"><strong>Replies</strong></div></td>
              <td width="250"><div align="center"><strong>Author</strong></div></td>
              <td width="250"><div align="center"><strong>Last Post</strong></div></td>
            </tr>
            <?php do { ?>
            <tr bgcolor="#FFFFFF">
              <td><a href="topic.php?topic_id=<?php echo $row_topics['topic_id'] ?>"><?php echo $row_topics['topic_subject'] ?></a> </td>
              <td width="75"><div align="center"><?php echo $row_topics['topic_num_replies'] ?></div></td>
              <td width="250"><div align="center"><?php echo $row_topics['topic_author'] ?></div></td>
              <td width="250"><div align="center"><?php echo $row_topics['reply_date'] ?> by <?php echo $row_topics['reply_author'] ?></div></td>
            </tr>
            <?php } while ($row_topics = mysql_fetch_array($topics)); ?>
          </table>

 

Many thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.