Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 673087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:24+00:00 2026-05-14T00:33:24+00:00

my primay key is user_id which is auto incremant UNSIGNED ZERO FILL , i

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:33:24+00:00Added an answer on May 14, 2026 at 12:33 am

    To display in PHP without leading zeros:

    echo (int) $val;
    

    To set the auto_increment value (this is not good practice, you should let MySQL handle primary keys for you!):

    mysql> CREATE TABLE test( id INTEGER AUTO_INCREMENT, data TEXT, PRIMARY KEY id(id) );
    Query OK, 0 rows affected (0.05 sec)
    
    mysql> INSERT INTO test VALUES (1,'23'),(2,'32'),(3,'3232');
    Query OK, 3 rows affected (0.00 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    mysql> SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'test';
    +----------------+
    | AUTO_INCREMENT |
    +----------------+
    |              4 |
    +----------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT MAX(id) FROM test;
    +---------+
    | max(id) |
    +---------+
    |       3 |
    +---------+
    
    1 row in set (0.00 sec)
    

    Then delete from test, check if the auto_increment is one above the max(id) in PHP, and if not:

    mysql> ALTER TABLE test AUTO_INCREMENT=3;
    Query OK, 3 rows affected (0.05 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a auto-incremented primary key: user_id. For a currently theoretical
Database: Table: news With the columns: Unique and Primary Key which auto increments called
I have a table users which has a primary key userid and a datetime
So, I have a subscriptions table: id - int(11) (With Primary Key) user_id -
There is a table: create table table1 ( id integer primary key, user_id varchar(36),
The value will be used as: from INTEGER UNSIGNED NOT NULL which defines different
I'm working no a site which stores individual page views in a 'views' table:
I'm submitting a form via HTML into a POST PHP page, which is then
Assume that I have a table user_count defined as follows: id primary key, auto
I have 3 tables - user, service and ratings. The user's primary key is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.