Hi guys,
I want to have an ID column with sequential integers so I can choose random ID numbers and select those rows. The problem is when I delete a row; it leaves a hole.
How should I handle this ? It would be great if I could shift them all down, so if I have 0,1,2,3,4 and remove ID 2 it becomes 0,1,2,3 and *not* 0,1,3,4.
Any help is appreciated.
Robert
Sequential Auto-Increment ?
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I've had cases which required sequencial id's.. so I would run a query like:
Code: Select all
mysql_query("DELETE FROM `table` WHERE `id` = '".$_GET['id']."' LIMIT 1");
mysql_query("UPDATE `table` SET `id` = (`id`-1) WHERE `id` >= '".$_GET['id']."'";