Posted by Adam Plocher on 01/20/06 19:45
Does this fix the problem? It will attempt to find the "replaceID"
automatically. You shouldn't need to shift every item, just the item
before or after the item you want to move.
function MoveUp($id)
{
$query = "SELECT ID FROM table WHERE SortOrder=(SortOrder+1)";
$ret = mysql_query($query);
if (mysql_num_rows($ret) == 1)
{
// if 0 rows returned, don't change the sortorder
list($replaceID) = mysql_fetch_row($ret);
$query = "UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id"
mysql_query($query);
$query = "UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID"
mysql_query($query);
}
}
Navigation:
[Reply to this message]
|