Page 1 of 1

[SOLVED] category order advice

Posted: Fri Feb 03, 2006 3:48 am
by rsmarsha
I have a categories table with an auto inc id, to which i want to add a new field containing a number to determine order.

As in order = 1 will be the first category shown. At the moment i was thinking of working it around calculating the highest order number and when a new cat is added, adding that as +1. To change the order i would have to take the current order of a cat, then -1 or +1 to that and alter the rest.

So if a category set to order = 2 wanted to be made order = 1 i'd have to run a query to set it to order = 1, then set the other category to 2.

Just wondered, is this is the best way to go about doing it?

Re: category order advice

Posted: Fri Feb 03, 2006 4:54 am
by raghavan20
rsmarsha wrote:I have a categories table with an auto inc id, to which i want to add a new field containing a number to determine order.

As in order = 1 will be the first category shown. At the moment i was thinking of working it around calculating the highest order number and when a new cat is added, adding that as +1. To change the order i would have to take the current order of a cat, then -1 or +1 to that and alter the rest.

So if a category set to order = 2 wanted to be made order = 1 i'd have to run a query to set it to order = 1, then set the other category to 2.

Just wondered, is this is the best way to go about doing it?
sorry..i could not understand when you say, "i want to add a new field containing a number to determine order.
" . If you do not mind can you provide examples of what you want to do.

Posted: Mon Feb 06, 2006 3:00 am
by rsmarsha
Ok if i have 3 categories:

Code: Select all

category_id  category_name category_order
1               test cat              1

2               testing               2

3               newcat               3
The categories are shown in the order of "category_order" so are shown as :

test_cat
testing
newcat


If i want newcat to move up one position, i would have to change it's "category_order" to 2and testing's to 3. I have up and down arrow buttons for shifting a cat's position.

To input the "category_order" number, i am working on the highest current number (in this case 3), and subtracting 1, then adding 1 to the cat which is moving down 1 position.

The problem with this is when a category is deleted it leaves a gap in "category_order", as a new category is added by calculating +1 to the current highest "category_order".

Any suggestions on the best way to work this?

Posted: Mon Feb 06, 2006 4:09 am
by rsmarsha
I have checked a forum software i use and am going to try their method. :)

Posted: Mon Feb 06, 2006 4:59 am
by rsmarsha
Sorted it now. :)