# Thread: Ranked # 5,537 out of 88,675

1. ## Ranked # 5,537 out of 88,675

Hello,

Have you ever seen a text like "Ranked # 5,537 out of 88,675" on a website? I want to implement something like this for one of my websites.

I have a site that provides free polls for webmasters. Every time someone votes on a poll, I increase the field "popularity" with 1. So this field shows how many votes the poll is receiving and thus how popular this poll is. What I want to do is show the owners how popular their polls are. I want to do this with the text "Popularity: ranked # 5,537 out of 88,675".

But how can I do this? Fetching the 88,675 is easy. That just the number of polls in the database. But how do I calculate the 5,537?

Example:
=======
poll 1: popularity=34
poll 2: popularity=17
poll 3: popularity=16
poll 4: popularity=5
poll 5: popularity=60

Ranks:
=====
poll1: "Popularity: ranked # 2 out of 5".
poll2: "Popularity: ranked # 3 out of 5".
poll3: "Popularity: ranked # 4 out of 5".
poll4: "Popularity: ranked # 5 out of 5".
poll5: "Popularity: ranked # 1 out of 5".

2. my_rank = SELECT COUNT(*) WHERE popularity > my_popularity ?

3. Yeah, I got it as soon as I posted the topic!

4. Which is better?

Example:
=======
poll 1: popularity=34
poll 2: popularity=17
poll 3: popularity=17
poll 4: popularity=34
poll 5: popularity=6

my_rank = [SELECT COUNT(*) WHERE popularity > my_popularity] + 1 gives:

Ranks:
=====
poll1: "Popularity: ranked # 1 out of 5".
poll2: "Popularity: ranked # 3 out of 5".
poll3: "Popularity: ranked # 3 out of 5".
poll4: "Popularity: ranked # 1 out of 5".
poll5: "Popularity: ranked # 5 out of 5".

or

my_rank = [SELECT COUNT(*) WHERE popularity >= my_popularity] gives:

Ranks:
=====
poll1: "Popularity: ranked # 2 out of 5".
poll2: "Popularity: ranked # 4 out of 5".
poll3: "Popularity: ranked # 4 out of 5".
poll4: "Popularity: ranked # 2 out of 5".
poll5: "Popularity: ranked # 5 out of 5".

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•