Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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