July 11th, 2013, 12:01 PM
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.
July 11th, 2013, 12:29 PM
July 11th, 2013, 01:00 PM
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?
July 11th, 2013, 01:15 PM