Page 1 of 1

Auto Increment with Letter

Posted: 2013-09-19 10:36
by AhmedBR
Hi Everyone,

Little Introduction:
I am a very happy user of AppGini been using it for the last few days and it solved a problem I had nicely.

The problem:
How to make a column with Auto Increment BUT with a letter (To be used as a customer code)
We usually do this with a trigger, but on the server I am working on this time, there is no trigger allowed!

The Way to go:
The HOOK functions came VERY VERY HANDY.
With some trial and error AND help - support of Ahmad (thank you) I got it to work, thought to share the solution with you.

The Solution:
Using the hook function Customers_after_insert

Use this code:
sql("update `Customers` set `CustomerIDLet`= 'CUS{$data['CustomerID']}' where `CustomerID` = LAST_INSERT_ID()", $eo);

The result:
The column CustomerIDLet would be something like this: CUS0001

Would like to this chance to say thanks to all the user who posted their tips here, I already used some of them. THANKS

Have a nice day from Brazil
Ahmed

Re: Auto Increment with Letter

Posted: 2013-09-19 10:37
by AhmedBR
The Code properly formatted:

Code: Select all

sql("update `Customers` set `CustomerIDLet`= 'CUS{$data['CustomerID']}' where `CustomerID` = LAST_INSERT_ID()", $eo);

Re: Auto Increment with Letter

Posted: 2013-10-14 01:21
by a.gneady
Thanks for sharing, Ahmed.

Re: Auto Increment with Letter

Posted: 2015-02-17 19:17
by clar1970
hi, I need somethig like that but in my case the structure is:

DPA-SPD-GCPGHJ-0001-2015 (fixed string=DPA-SPD-GCPGHJ-, 0001= consecutive per year, 2015=actual year) every year initialize 0001