I have auto increment fields in mysql database, that is my id when I remove on of the my items the next field id is starting after deleted number.
For Example: my content from 1 to 100, when I remove these contents (from 1 to 100), and insert other contents, The id is 101, I need the id to be 1 and start from 1 again or start from the smaller number in MySQL id field
EDIT: I have a CMS , in CMS the user can delete some rows, and I need other auto increment update automaticaly
I think there is no option in MySQL to do this, but if you have a CMS and need to sorting auto-increment fields by MySQL, I know a better way that is fetching auto-increment fields value and put them in an array and then work with that array, for example This is your database table:
id | name
and this is the value of your table:
25 | Ali
36 | Alex
37 | Reza
39 | Steven
40 | Mohammad
Then fetch this values and put them in array and then work for that from 0 to the end (count of fields on table):
for example You can have access to the each value what you want from 0 to end:
echo $array[0];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments