Jump to content

Last Post


Ashoar

Recommended Posts

I have run into a little problem.

 

I have a section of code that included a MYSQL query.

This piece of code fetches and displays all the forum boards on the main page plus the posts, threads and last post for each board.

 

This is the code:

$boards = mysql_query("SELECT f.forum_name,
       f.forum_desc,
       f.board,
       COUNT(DISTINCT p.post) AS threads,
       MAX(p.showtime) AS showtime,
       MAX(p.title) AS title,
       SUM(p.numreplies) AS reply
  FROM forums AS f
       LEFT JOIN post_reply AS p ON p.board=f.board
GROUP BY f.forum_name,
          f.forum_desc,
          f.board
ORDER BY f.forum_id asc")  
or die(mysql_error());

$boards2 = mysql_num_rows($boards);
for($count = 1; $count <= $boards2; $count++)
{
$board = mysql_fetch_array($boards);

print "<tr class='mainrow'><td><center><img src='/images/onoff.jpg'></center></td><td><A href='board.php?board=".$board['board']."'>".$board['forum_name']."</a><p>".$board['forum_desc']."</p></td><td>On ".$board['showtime']."<br><br><A href='member_profile.php?post=$board[title]'>$board[title]</a></td><td><center>".$board['threads']."</center></td><td><center>".$board['reply']."</center></td></tr>";
}
print "</table>";
?>

 

The problem is that i cannot get the last post/reply of each board.

The last reply, in this code is "Title" in the MYSQL query.

I am using MAX in the MYSQL query but it doesn't seem to be fetching the very last entry from the selected row.

Would their be a way to change this through php to grab the very last entry in that row or is their an alternate to MAX?

 

Or is their a way to change this code, so that i can order, only the title, by lastrepliedto?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/155334-last-post/
Share on other sites

Nah i cannot do it like that.

The current  ORDER BY f.forum_id asc")  orders the actual boards on the main page.

If i change that the boards starts changing around.

 

I thought i would be able to do this:

MAX(p.title) AS title ORDER by lastreplied asc,

 

But that just gives errors.

Link to comment
https://forums.phpfreaks.com/topic/155334-last-post/#findComment-817239
Share on other sites

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.