The best way to do it would be as follows:
1. Add an extra column into your table - this will be the id that you will use to reference the page, as a pose to the primary key. As it will be a highly used search column I would index it, but 'tis up to you.
2. When inserting a page / image into your table, before the insert satement run something like this:
CODE
$sql = "SELECT sortOrder FROM project ORDER BY sortOrder DESC LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$sortorder = intval($row['sortOrder']) + 1;
that means that you now have the next highest sort order ready to insert into your new record (the same way as an auto-increment works)
3. Run your insert statement, inserting your new 'next highest sort number' in your new column.
// INSERTS OVER, GRAND, NOW FOR THE DELETE AND UPDATE
4. When you delete an item, pass the sort number aswell as the id :
CODE
mysql_query('DELETE FROM projects WHERE projectId = '.(int)$_REQUEST['id']);
//BELOW IS THE CODE THAT WILL UPDATE THE REST OF YOUR ITEMS
mysql_query('UPDATE projects SET sortOrder = (sortOrder - 1) WHERE sortOrder > '.(int)$_REQUEST['sortorder']);
Now, that means you can go from 1 -> number of projects you've got without missing any numbers and you'll always have a record for it, even if the row id's are all over the place.
Reason for doing all this: It's easier than trying to controll the auto-increment on a primary key.
I'm away to get pished now so I won't be back on till monday, but there's plenty of top coders in this forum that would be glad to help ya if you're still stuck.
Good Luck
This post has been edited by pemcconnell: 22 Aug, 2008 - 08:02 AM