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 Quote Link to comment 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); ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.