Michdd Posted July 18, 2009 Share Posted July 18, 2009 Is there a way I can get the last 3 results of a query in ASC order without running more than one query? I know I can do this way: $query = "SELECT * FROM `table` LIMIT " . (Query to count results) - 3 . ", 3"; But is there a better way? Link to comment https://forums.phpfreaks.com/topic/166455-solved-last-3-results-asc-without-2-queries/ Share on other sites More sharing options...
ldougherty Posted July 19, 2009 Share Posted July 19, 2009 Sorting it ASC is what makes your second query necessary. If you wanted to select the last 3 results you could do DESC LIMIT 3 If you wante to do DESC LIMIT 3 you could then reverse the results array with array_reverse http://us2.php.net/manual/en/function.array-reverse.php Link to comment https://forums.phpfreaks.com/topic/166455-solved-last-3-results-asc-without-2-queries/#findComment-877787 Share on other sites More sharing options...
Michdd Posted July 19, 2009 Author Share Posted July 19, 2009 Oh, good idea thanks. Link to comment https://forums.phpfreaks.com/topic/166455-solved-last-3-results-asc-without-2-queries/#findComment-877789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.