Jump to content

Sorting


Deivas

Recommended Posts

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 ____|

+------------------+---------+

Link to comment
https://forums.phpfreaks.com/topic/197500-sorting/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036797
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/197500-sorting/#findComment-1036814
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.