TeddyKiller Posted May 27, 2010 Share Posted May 27, 2010 If I had an query with ORDER BY date ASC LIMIT 3. It would display 30 minutes ago 10 minutes go 7 minute ago but I want to display the 3 most recent ones in ASC order.. So if it goes like.. 30 minutes ago 10 minutes go 7 minutes ago 5 minutes ago 3 minutes ago 1 minute ago so If I want to display the 3 most recent ones in ascending order, it'll look like this.. 5 minutes ago 3 minutes ago 1 minute ago if you understand.. here is my query. Quite a beast. $statusq = $db->execute("SELECT c.comment, c.date, u.id, u.avatar, u.displayname FROM `status_comment` as c, `users` as u WHERE c.status_id = '".$row['id']."' AND u.id = c.user_id ORDER BY c.date ASC"); This displays in the order my first one displays... sorry I went in all kinds of order. xD Hopefully you can help me? Quote Link to comment https://forums.phpfreaks.com/topic/203122-order-by-asc-limit-3-display-the-3-most-recent/ Share on other sites More sharing options...
TeddyKiller Posted May 27, 2010 Author Share Posted May 27, 2010 Sorry if I didn't make it clear.. if I have these results.. 30 minutes ago 10 minutes go 7 minutes ago 5 minutes ago 3 minutes ago 1 minute ago I want to display the 3 most recent ones.. so, 5, 3 and 1. In ascending order... I just can't think how to do it.. Quote Link to comment https://forums.phpfreaks.com/topic/203122-order-by-asc-limit-3-display-the-3-most-recent/#findComment-1064305 Share on other sites More sharing options...
Jumpy09 Posted May 27, 2010 Share Posted May 27, 2010 Working together we came up with *$statusq = $db->execute(" SELECT a.* FROM ( SELECT c.comment, c.date, u.id, u.avatar, u.displayname FROM `status_comment` as c, `users` as u WHERE c.status_id = '".$row['id']."' AND u.id = c.user_id ORDER BY c.date DESC LIMIT 3) a ORDER BY a.date ASC"); which works. Quote Link to comment https://forums.phpfreaks.com/topic/203122-order-by-asc-limit-3-display-the-3-most-recent/#findComment-1064341 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.