Auto Increment with Letter
Posted: 2013-09-19 10:36
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
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