Dynamically renumber the rows:

 

Use a temp table – it contains, at a minimum, your primary key and an autonumber field. 

 

Grab the records from the database, ordering by whatever column you’re using to determine order, and insert into your temp table.  At this point, they will be represented with the ordering in perfect, sequential access.  Then update your original table, using the values from the temp table (using an update query with a join)

 

To update the order, create a stored procedure that accepts your primary key, and the position.  Update all records that have an order value greater than or equal to the new position by incrementing by one.  Then run the code to update the order as described above.

 

**************************

Billy Cravens

Web and Software consulting

www.Architechx.com

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Bruce Sorge
Sent: Friday, September 06, 2002 7:53 PM
To: [EMAIL PROTECTED]
Subject: Sorting Issue

 

Hello list. I am trying to do something that I know has been done before.

 

I have a list of promotions that I am getting from a database, and listing them by a field called Order. These promotions also have a unique ID with them.

I output them to a table and, to the right of each promotion title there is an up/down arrow so that the user can move them around. I know how to move them around in the browser, but I want to actually update the order in the database. The problem that I am having is making sure that I only change the order of the promotion just one above or below it, as well as the one I am moving. I am passing in the promotion ID and the Order number of the promotion that I want to move. So, how do I query for the record immediately above or below the one that I am moving? Does this make sense?

 

Thanks in advance,

 

Bruce

 

Reply via email to