EchoFool Posted January 17, 2010 Share Posted January 17, 2010 Hey, I have a query which orders by in ASC and limits 20, but this is the reverse of what i need as i need the "last 20" rows (the most up to date) but still in ASC order.... currently ORDER ASC LIMIT 20 gets 0 to 20. How can i get the last 20 rows of a result in a query? Quote Link to comment https://forums.phpfreaks.com/topic/188826-select-last-x-amount-of-rows/ Share on other sites More sharing options...
premiso Posted January 17, 2010 Share Posted January 17, 2010 You need it in ASC order? Well you can always store the end results in an array and rsort the array: SELECT * FROM table ORDER BY field DESC LIMIT 10 Should get you what you want, you will just have to manipulate the data when PHP has it. Quote Link to comment https://forums.phpfreaks.com/topic/188826-select-last-x-amount-of-rows/#findComment-996872 Share on other sites More sharing options...
EchoFool Posted January 17, 2010 Author Share Posted January 17, 2010 So like: <?php //query $row = mysql_fetch_assoc($Query); //sort $row to ASC order some how For each { // stuff } ?> ? Like that? Quote Link to comment https://forums.phpfreaks.com/topic/188826-select-last-x-amount-of-rows/#findComment-996873 Share on other sites More sharing options...
kickstart Posted January 18, 2010 Share Posted January 18, 2010 Hi Or SELECT * FROM (SELECT * FROM table ORDER BY field DESC LIMIT 20) a ORDER BY field All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/188826-select-last-x-amount-of-rows/#findComment-997195 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.