| 
	
 | 
 Posted by Adam Plocher on 01/20/06 18:51 
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] 
 |