Thanks for the suggeestions Roger 🙂
I was thinking about this whilst cycling home last night (how sad am I?) I got a similar idea through my head as your suggestion.
See you have to rely on the priority list being unique withough constricting it in the DB which mean you have to check all records on input (no problem there) and when you move it.
So assuming the data is in this state we can easily do what I want with a choice of statements.
If I'm moving a record up or down one place then I only need to update 2 records. The one moving up one place (from 25 to 24 for example) and the record that is currently 24 down to 25.
With that in mind its a simple case of two updates
UPDATE table SET priority = 25 where priority = 24;
and
UPDATE table SET priority = 24 where urn = $urn;
Taking this further to put it up more than one place at a time I have to do a slightly bigger update and again I can do that in 2 updates. Again the record Im moving is going up in priority.
UPDATE table SET priority = priority + 1 WHERE priority >= $priority_value;
and
UPDATE table SET priority = $priority_value WHERE urn = $urn;
Hope that makes some sense 🙂
Any more suggestions let me know.