tidus97 Posted January 16, 2009 Share Posted January 16, 2009 i have an id row in my table that auto increments. lets pretend i have 1 2 3 4 and 5 if i delete 4, i am left with 1 2 3 5. i want to reorder it so i get 1 2 3 4 i found out how to do this last night...lost the link. :/ it was very simple Link to comment https://forums.phpfreaks.com/topic/141035-reorder-mysql-autoincrement/ Share on other sites More sharing options...
RussellReal Posted January 16, 2009 Share Posted January 16, 2009 idk if that works I used to mostly do just a foreach loop.. but this looks like it should work =\ <?php $array = array("0" => "a","1" => "b", 3 => "d"); $arrKey = range(0,count($array) - 1); $array = array_combine($arrKey,$array); ?> Link to comment https://forums.phpfreaks.com/topic/141035-reorder-mysql-autoincrement/#findComment-738197 Share on other sites More sharing options...
chronister Posted January 16, 2009 Share Posted January 16, 2009 Just out of curiosity, why do you want to re-order them so that your never missing a number? typically the auto-increment id is basically just used for identifying the row in the db so you can select it, or modify it in some way. Basically I treat the auto-increment id as something only the code cares about and that no human is going to need for any reason.... If I need id's that humans need then I will make a new id field for that purpose. I have seen people wanting to do this before, and have never heard a good reason for doing so. Nate Link to comment https://forums.phpfreaks.com/topic/141035-reorder-mysql-autoincrement/#findComment-738203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.