SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ranking/ordering data

    Hi

    I am wondering if anyone had an easy solution for ranking data in a DB. Say we have a table with artists or bands and we want to set up a ranking field that could change regularly, e.g...

    id | name | rank
    1 | U2 | 1
    2 | Train| 2
    3 | Cold play | 3
    4 | Chilli Peppers | 4

    Now say you want to move the Chilli Peppers to be ranked number 2. Then Train would need to become ranked 3 and Cold Play ranked 4. Is there any setting you can use that will shuffle all the rankings based on moving just one?

    I suppose you could get all these details out of the table and set up some script to handle it and re-insert the records but that is going to be a lot of trouble when ou have several hundred or even thousand records.

    Got any ideas?

    thx

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    update artist
    set rank = rank + 1
    where rank >= 2

    update artist
    set rank = 2
    where id = 4


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
  •