I know this post is old but here is a little code that I used to delete any number of items and still keep the proper order for the remaining:
$this->dbh->autocommit();
$deletedSlots = 0;
while ($queryObject->fetch()) {
if($input->slotDelete[0] == $queryObject->ss_id) {
$ok = $this->dbh->query("
DELETE FROM {$this->conf['table']['ss']}
WHERE ss_id = '$queryObject->ss_id'
AND screensaver_name = '$input->slotType'
");
$deletedSlot = array_shift($input->slotDelete);
$deletedSlots++;
}
else {
$ok = $this->dbh->query("
UPDATE {$this->conf['table']['ss']}
SET slot = slot-".$deletedSlots."
WHERE ss_id = '$queryObject->ss_id'
AND screensaver_name = '$input->slotType'
");
}
}
if($this->dbh->commit()) {
//success
}
else {
//error
}
Basically it just increments a counter every time an item is deleted, shifts the deleted item array, and sets the next order to itself - counter value.
So, if you had 1,2,3,4,5,6 and deleted 2,5 it would loop as the following:
1 as itself;
2 deleted, counter++;
3 as itself - counter (becomes 2);
4 as itself - counter (becomes 3);
5 deleted, counter++;
6 as itself - counter (becomes 4);
Of course you could add some checking like if the value is still equal to itself, like in the case of number 1, do nothing to save a hit to the DB.
-Scott