Sorting, auto change value on same values
Posted: Wed Nov 19, 2008 3:42 am
I have an 'order' column which defines the order some sql results will be ordered by. I have a form with textfields to quickly change the items' order like,
Order | Item
[ 1 ] item1
[ 2 ] item2
[ 3 ] item3
[ 4 ] item4
[ 5 ] item5
[ 6 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
[ ReSort ]
Now the problem is that the 'order' column can have one or more equal values like,
Order | Item
[ 1 ] item1
[ 1 ] item2
[ 7 ] item3
[ 4 ] item4
[ 1 ] item5
[ 7 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
and in that case they will be sort by order and next, for the rows that have same values, are ordered by modified date, (I think),
What I want to do is auto rearrange the values so they can never have same values,
for e.g. user changes item's 2 order value to be 1, but there is already a value 1, so when we resort the values it becomes like this,
Order | Item
[ 1 ] item2
[ 2 ] item1
[ 3 ] item3
[ 4 ] item4
[ 5 ] item5
[ 6 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
item's 2 value changes to 1 and automatically item's 1 value (which was 1) changes to the next possible, that is 2.
Any help on this?
Order | Item
[ 1 ] item1
[ 2 ] item2
[ 3 ] item3
[ 4 ] item4
[ 5 ] item5
[ 6 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
[ ReSort ]
Now the problem is that the 'order' column can have one or more equal values like,
Order | Item
[ 1 ] item1
[ 1 ] item2
[ 7 ] item3
[ 4 ] item4
[ 1 ] item5
[ 7 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
and in that case they will be sort by order and next, for the rows that have same values, are ordered by modified date, (I think),
What I want to do is auto rearrange the values so they can never have same values,
for e.g. user changes item's 2 order value to be 1, but there is already a value 1, so when we resort the values it becomes like this,
Order | Item
[ 1 ] item2
[ 2 ] item1
[ 3 ] item3
[ 4 ] item4
[ 5 ] item5
[ 6 ] item6
[ 7 ] item7
[ 8 ] item8
[ 9 ] item9
item's 2 value changes to 1 and automatically item's 1 value (which was 1) changes to the next possible, that is 2.
Any help on this?