I’m using auto-increment to assign a id to every new entry in my database.
Also, i’ve got a php-script which is selecting 10 entrys from this database, according to the current pagenumber.
For example, if the current page is 2, the script should select every entry between id=20 and id=29.
Now, if i delete an entry, the id is lost. Therefore the script will only show 9 entrys when id28 has been deleted.
Is there a way to reassign the auto-increment values after e record has been deleted?
This is usually considered desirable: if entry number
28is deleted, there will never again be an entry28. If someone ever tries to refer to it, they’re clearly trying to refer to the one that’s been deleted, and you can report an error.If you went back and reassigned
28to some new entry, now you have no idea whether the person meant the old28or the new record.Let’s take a step back and revisit what you want to do. Your goal is not to show ten entries between
20and30. Your goal is to show ten entries that meet your criteria. For that, you can use the built-inLIMITandOFFSETterms:The
OFFSETtells MySQL where to start counting andLIMITtells it how many to count. MySQL will put together the whole result set, then give you 10 entries beginning at the 30th one. That’s your fourth page of results. It does not remotely matter now what IDs they happen to have.