my primay key is user_id which is auto incremant UNSIGNED ZERO FILL, i want to display user_id on a page without leading Zero( means 1 instead of 0000000001 )..
how can we do that in php or in mysql
one more question…
if i delete last record( let user_id=21) wwhich have highest id of that table then can we adjust auto increment value to 21 instead of 22 of that table.
To display in PHP without leading zeros:
To set the auto_increment value (this is not good practice, you should let MySQL handle primary keys for you!):
Then delete from test, check if the auto_increment is one above the max(id) in PHP, and if not:
As you had 3 records, auto inc was 4, deleted 1 so 2 records, auto inc should be the next value so set it to 3.
As above, this is not good practice and you could end up with messy data if you don’t lock the tables while performing these auto_inc queries – sacrificing performance for primary key order doesn’t seem sensible!