Jump to content

Looking for the best approach (Setting an order)


tryingtolearn
Go to solution Solved by vinny42,

Recommended Posts

I am looking for some advice on the best way to maintain an options system.

I have a list of items (In a mysql table) that make up options or packages that can be ordered

 

For example

Combo 1 comes with

-List Item Orange

-List Item Grape

-List Item Brick

 

Combo 2 comes with

-List Item Grape

-List Item Salmon

-List Item Tiger

 

Combo 3 comes with

-List Item Orange

-List Item Brick

-List Item House

-List Item Red

-List Item Blue

-List Item Car

-List Item Boat

-List Item Plane

 

etc...

 

The issue is that the list items have to be displayed in a specific  order and new list items are added on regular intervals and others are deleted.

I was going to add a column to the DB with a # order so I could just ORDER the result based off that but say there are 30 items and I need to add a new item in position 2 everything below it needs to be renumbered.

 

Is there a better approach to this system? Any advice is appreciated, thanks

 

 

Link to comment
Share on other sites

  • Solution

 


 but say there are 30 items and I need to add a new item in position 2 everything below it needs to be renumbered.

 

True, but that is one query:

 

UPDATE table SET order_column = order_column+1 WHERE order_column >= X;

where X is the order_column value of the first record that needs to be moved. 

And you could even stick that in a trigger and not have to worry about it ever again. :-)

 

You should perhaps use a separate table for this data, the sortorder itself is not part of the daa being sorted and if you ever decide to sort the same items differently in two dropdowns (of wherever) you don't want to have to add a new column every time.

Link to comment
Share on other sites

 


Maybe a better way, but you could have a large increment in the order numbers, like 100, 200, 300, etc...

 

You could do that; make large gaps and put new numbers right in between. inserting between 100 and 200 yould be 150, between 100 and 150 at 125 etc. But in the end that's just postponing the envitable, you will have to renumber some time.

Link to comment
Share on other sites

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.