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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.