I'm doing a little work with PHP, and I need help removing a record from a table. I insert data, and then delete it, but the auto_increment continues at the last inserted position. I want that when deleting a data, the auto_increment also "does" it and resets to the previous value. Is it possible? I just ignore it? I greatly appreciate any help.
Go to the "Operations" tab in phpmyadmin and when it opens look for the "auto increment" field. Put "1" and you're done. That for each table within your database.
To edit it from code, just do this:
Note: The value of "1" is not required. You can do this to get the value of the autoincrement:
And once you get the last ID (this is before removing the last element, as you mentioned in your question), you subtract "1", and that value is what goes into:
I hope my answer helps you. Cheers!
PS: Depending on how you handle yourself in your code, it is recommended that you use this practice. Since if at some point you need to show all the records you have in your table, you don't decrement the id of the auto-increment, and you don't make the if(mysqli_num_rows($response)>0){//send/show data} statement , Errors will occur due to "id"s not existing after being deleted in the past. So whether you do this extra check I just mentioned or alter the table's auto_increment, both could be considered practical and well-used solutions. Luck!