Insert order, increment other entries

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Insert order, increment other entries

Post by Chalks »

I'm building a system for users to create/delete pages for a dynamic menu. One of the things I want to be able to do is have the user input a number (any integer) and have that number determine page order. The difficult comes when the user is trying to replace a page in the order. For example:

EXISTING:
Index (1)
Cheese Wiz (2)
Blue Cheese (3)

INPUT:
Cheddar Cheese (2)

now, the order of Cheese Wiz needs to be 3, and Blue Cheese needs to be 4.

Is there any way to increment several rows of data by one all at once? I really don't want to make several queries to update several different pages.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Insert order, increment other entries

Post by jaoudestudios »

I think you will have to do multiple queries, but you could do an sql transaction - this will improve performance and will secure the system as if one query fails the whole system rollbacks (undo).
Post Reply