Ashoar Posted April 23, 2009 Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155334-last-post/ Share on other sites More sharing options...
MadTechie Posted April 23, 2009 Share Posted April 23, 2009 Maybe reverse the order and limit to 1 ie ORDER BY p.showtime DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/155334-last-post/#findComment-817238 Share on other sites More sharing options...
Ashoar Posted April 23, 2009 Author Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155334-last-post/#findComment-817239 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.