// NOT TESTET, just to show concept
function MoveToTop($id)
{
// get the priority of the item, and the max priority available
$item = mysql_fetch_assoc(mysql_query("SELECT priority, MAX(priority) AS max_priority FROM table WHERE id = ".$id));
// move all items above the current item, one prioroty down.
mysql_query("UPDATE table SET priority = priority - 1 WHERE priority >= ". $item['priority']);
// set priority of the current item to the max priority
mysql_query("UPDATE table SET priority = ".$item['max_priority']." WHERE id = ".$id);
// Reorder() could be called here, to make absolutely sure everything is in order...
}
// NOT TESTET, just to show concept
function MoveToBottom($id)
{
// get the priority of the item.
$item = mysql_fetch_assoc(mysql_query("SELECT priority FROM table WHERE id = ".$id));
// move all items below the current item, one priority up (to make room)
mysql_query("UPDATE table SET priority = priority + 1 WHERE priority <= ". $item['priority']);
// position the current item at priority 0 (zero)
mysql_query("UPDATE table SET priority = 0 WHERE id = ".$id);
// Reorder() could be called here, to make absolutely sure everything is in order...
}
Bookmarks