Jump to content

Recommended Posts

Hi

 

I have a table which has the following fields (amoung others)

 

Id = Int Unique id.

TestId = Int

ClauseId = Int

Order = Int

 

Basically in code a test has several clauses which are checked in order specified in the order column. This works fine. TestId, ClauseId and Order combined are unique.

 

I want to provide a function to swap around the order (ie, allow a superuser to shuffle a clause up or down).

 

However my mind is a blank as to an elegant way of doing this. Can do it in multiple stages (ie, renumber one to 0, then the other to the firsts original number then the first back to the 2nd ones number).

 

I am sure I have missed something obvious though and there must be an elegant way of doing this.

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/188691-swapping-order-column-elegantly/
Share on other sites

Hi

 

Err, think I missed explaining it correctly.

 

Problem is that whichever order I do it in it will fail as there is a duplicate unique index.

 

If 2 becomes 1 and 1 becomes 2 then at some point momentarily both will be 1 or both will be 2.

 

I can see a few ways of doing it (delete both and reinsert, update one to a special value then update the 2nd to the 1st value and then update the 1st to the 2nd original value), but nothing elegant.

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.