Попробуйте это -
// NOT TESTET, just to show concept.
function Reorder()
{
// query to get all id's, ordered by priority ASC.
$things = mysql_query("SELECT id FROM table ORDER BY priority ASC");
// iterate thru all items, and give each a new priority
$priority = 0;
while($row = mysql_fetch_assoc($things))
{
mysql_query("UPDATE table SET priority = ".$priority." WHERE id = ".$row['id']);
// add 1 to $priority, then the next item will have a higher priority of 1.
$priority++;
}
}
Это для переупорядочения ваших функций, и тогда вы можете просто переместить одну функцию вверх и одну вниз:
// 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...
}