#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,987
    Rep Power
    375

    Ordering a list using custom values (e.g. numbers)


    in my database i have: table (category, weighting,..)

    i want to be able to order the category using weighting field. I know it needs to be a number (ideally). The problem is when i add a new category, how do i "do something" so the new category's weighting is before/after some other category? if that makes sense.

    Googling didnt help much except for a thread on overstack suggesting i use bigger numbers 10000, 20000 so if i need to place a category in between i can use a no in between. I personally dont like this approach.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,987
    Rep Power
    375
    maybe i am over thinking it but i think that it will be too much hassle? how do i even do the UI when a user adds a category? i was thinking something like a drop down box which says "after travel", "after finance" etc. but if they select travel, for example. how do I then "Re-number" all categories after travel?

    do i issue a blanket update saying update table set weigh = weigh +1 where weigh >= the "chosen_weight"? then assign the new category that weight?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398

IMN logo majestic logo threadwatch logo seochat tools logo