Deivas Posted April 3, 2010 Share Posted April 3, 2010 For example... I have: +------------------+---------+ | ID____________| VOTES_ | +------------------+---------+ |1_____________ | 55 ____| +------------------+---------+ |2_____________ | 99 ____| +------------------+---------+ ... and how can I make so it will be like this: +------------------+---------+ | # ____________| VOTES_ | +------------------+---------+ |1_____________ | 99 ____| +------------------+---------+ |2_____________ | 55 ____| +------------------+---------+ Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/ Share on other sites More sharing options...
Deivas Posted April 3, 2010 Author Share Posted April 3, 2010 Ok, When I do SELECT name, votes AS votes, @num := @num +1 AS Rank FROM `servers` a, ( SELECT @num :=0 )b ORDER BY votes DESC LIMIT 0 , 10 and when I go to the next page, it starts from 1 again? Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036585 Share on other sites More sharing options...
ignace Posted April 4, 2010 Share Posted April 4, 2010 SELECT votes FROM table ORDER BY votes DESC $i = 1; while (list($votes) = mysql_fetch_row($result)) { echo $i, ' ', $votes, '<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036675 Share on other sites More sharing options...
fenway Posted April 4, 2010 Share Posted April 4, 2010 SELECT votes FROM table ORDER BY votes DESC $i = 1; while (list($votes) = mysql_fetch_row($result)) { echo $i, ' ', $votes, '<br>'; } What does that even do? OP: you're talking about paging nwo? Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036790 Share on other sites More sharing options...
GoneNowBye Posted April 4, 2010 Share Posted April 4, 2010 the limit clause works as so Limit 5 is the same as Limit 0,5 which means limit to 5 rows after the zeroth row (start) limit 5,5 means limit 5 rows after the fith row (return 5 from the 5th, so page two) limit 1,100 return 100 rows after the first returned rows (see rows 2-102) (starting from row one) you want limit ((page_number-1)*number_per_page),number_per_page assuming your pages start at one that way the 1st page is limit of 0 to number per page. many people think its the row range returned, that 10, 100 returns 90 rows, from the tenth to the hundreth, but its not its 100 rows after teh tenth result. hope i helped Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036797 Share on other sites More sharing options...
ignace Posted April 4, 2010 Share Posted April 4, 2010 SELECT votes FROM table ORDER BY votes DESC $i = 1; while (list($votes) = mysql_fetch_row($result)) { echo $i, ' ', $votes, '<br>'; } What does that even do? Create +------------------+---------+ | # ____________| VOTES_ | +------------------+---------+ |1_____________ | 99 ____| +------------------+---------+ |2_____________ | 55 ____| +------------------+---------+ As derived from SELECT name, votes AS votes, @num := @num +1 AS Rank FROM `servers` a, ( SELECT @num :=0 )b ORDER BY votes DESC LIMIT 0 , 10 There is no need for MySQL to create the rankings if they are merely for show Quote Link to comment https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036814 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.