vang163 Posted August 12, 2008 Share Posted August 12, 2008 hi, i've a table with 100 records. i displayed the data into 10 records per page, therefore i've 10 pages of data. using this query - "select * from table order by $column $direction limit $set_limit $limit_size" where $column is the table column name $direction - asc or desc Assuming i'm at page 1, I can view the display data (1,2,3,4..10) in ascending order by default. But when i want to display the data in descending order for page 1, I'm getting descending order data from page 10. I want to be able to see the page 1 data in ascending and in descending order. This applies to all other pages. (2,3,4...10) Can someone show me how this can be done, thanks. Link to comment https://forums.phpfreaks.com/topic/119319-order-by/ Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 When you order by DESC you have to select the last 10 rows, rather than the first 10. I'm not sure if there's a quick way to do this with pure-SQL, but you could simply dump the ASC results into an array, and use array_reverse() if you wanted to display them in reverse order. Link to comment https://forums.phpfreaks.com/topic/119319-order-by/#findComment-614653 Share on other sites More sharing options...
vang163 Posted August 13, 2008 Author Share Posted August 13, 2008 hi, i have no idea how to dump the ASC results into an array, can you show me how? my initial idea was below but it does not work. $sql = "select * from table"; $result = mysql_query($sql); $asc = mysql_fetch_assoc($result); $reverse_result = array_reverse($asc); Link to comment https://forums.phpfreaks.com/topic/119319-order-by/#findComment-615578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.