SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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".
    Ballot-Box.net - free polls for webmasters
    FormLog.com - free form processor

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my_rank = SELECT COUNT(*) WHERE popularity > my_popularity ?

  3. #3
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I got it as soon as I posted the topic!
    Ballot-Box.net - free polls for webmasters
    FormLog.com - free form processor

  4. #4
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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".
    Ballot-Box.net - free polls for webmasters
    FormLog.com - free form processor


Bookmarks

Posting Permissions

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