|
Posted by Jon on 01/20/06 19:11
Ok, I've added a linkOrder ID into the DB, and have my up/down arrows
passing order=up and order=down now - My problem now is not incrementing or
decrementing the current id chosen, it's finding the OTHER IDs that will be
affected. Do I literally decrement every orderID for the current pageID? If
the pageIDs are scattered, I really will not know at all what the current ID
is save what came from the DB.
"Adam Plocher" <aplocher@gmail.com> wrote in message
news:1137775896.954286.291340@g49g2000cwa.googlegroups.com...
> This is how I normally achieve a sortable list:
>
> You should start by setting up a SortOrder (int) column. Each new
> record that get's added should cause that # to increment. If this is
> going to be a multi-user system or something you should increment it
> based on that UserID (so there aren't gaps in the number). Then when
> you want to move up simply do:
>
> function MoveUp($id,$replaceID)
> {
> UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id
> UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID
> }
>
> move down would be similar
>
> function MoveDown($id,$replaceID)
> {
> UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$id
> UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$replaceID
> }
>
> And of course on your select you would ORDER BY SortOrder. There are
> several ways you can accomplish this task, this is just the way I do
> it. I don't know if this is necessarily the best way, but as long as
> your script doesn't leave gaps in the SortOrder # you'll be fine.
>
Navigation:
[Reply to this message]
|