Auto increment number in a textbox

Yong Scott
Yong Scott used Ask the Experts™
on
Hi expert , any solution for me to generate auto increment number starting from 735/2018 in column  registration number of  textbox html.. then 736/2018 when new entry  is insert.
Capture.PNG
i wish registration number in my textbox can auto increment starting 735 then 736 ... so on
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
suggest to have an ajax call to the backend script to grab the latest auto incremental number and display it into your textbox (or a div/span, etc in HTML), not only depends on client side scripting to make the auto increment. In addition, you may need to think for concurrency issues, such as if 2 different users logging in 2 different areas, what will be displayed etc.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Few ways of dealing with this depending on your needs. Are you wanting the next number BEFORE you insert into the database, or are you happy to get it after the INSERT? Is the 2018 set in stone or would that change based on the year. If it's based on the year, does the 735/736 etc reset to 1 for the next year.

If the auto increment just carries on and you only need the ID AFTER the insert, then a simple Auto Increment field in your DB would be sufficient - it would be generated automatically when the record was inserted. This would take care of the first part of your number, and you could easily build the full xxx/2018 format when needed for display.
NerdsOfTechTechnology Scientist
Commented:
Consider creating a timestamp column and an ID auto-increment column.

That way the ID's will continue to grow dynamically, while you can generate a sequence of {seq}/{year} based on a ROW_NUMBER() OVER() query easily.


seq/year AS bapreg, bapID, bapdate

2/2019, 52000, 1/4/2019
1/2019, 51999, 1/2/2019
...
400/2018, 51201, 9/2/2018
399/2018, 51200, 9/2/2018
...
612/2017, 50101, 11/15/2017
611/2017, 50100, 11/14/2017
NerdsOfTechTechnology Scientist

Commented:
Information provided should help OP achieve goal. An autoincrement ID and date field can help create a composite ID of either row()-within-year/year, or simply id/year if sequential order in the year is not important.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial