You must Sign In to post a response.
  • Category: General

    How To Generate and Save Auto Increment UserId with Prefix using Php Mysql

    Hi Developers,

    I need to generate unique auto increment user id with Prefix in Php
    and also save it to the database.
    ]My required Output is like EMP001,EMP002,EMP001.......................... to EMP00n n numbers
    This is the first step in my project
    i don't know php is well.

    so please help me to generate unique id using php code and also save it into the database.


    Thanks with
    Paul.S
  • #767454
    If the prefix "EMP" is constant, you can simple concatenate "EMP" with auto generate user id.
    I am not familiar with PHP. Is it very complex in PHP?.

    If you are nor familiar with PHP do not directly jump into the project. First read some good tutorials then start your project.

    By Nathan
    Direction is important than speed

  • #767455
    Ok nathan thanks for your quick reply

    Paul.S

  • #767485
    Hi,

    You can do this in 2 ways, one is AutoIncrement the field while creating table itself and another one is increment the field value while insert the record.

    1)

    CREATE TABLE [dbo].[Employee](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [EmpNo] AS ([PreFix]+ RIGHT('0000000' + CAST(Id AS VARCHAR(7)), 7)) PERSISTED,
    CONSTRAINT [PK_AutoInc] PRIMARY KEY ([ID] ASC)
    )


    2)

    DECLARE @EmpNo VARCHAR(25);
    SELECT @EmpNo = @PreFix + RIGHT('0000000' + CAST(@Id AS VARCHAR(7)), 7)
    --use the above EmpNo while insert it into database


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments