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
Auto Increment with Letter
Auto Increment with Letter
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper
Re: Auto Increment with Letter
The Code properly formatted:
Code: Select all
sql("update `Customers` set `CustomerIDLet`= 'CUS{$data['CustomerID']}' where `CustomerID` = LAST_INSERT_ID()", $eo);
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper
Re: Auto Increment with Letter
Thanks for sharing, Ahmed.
AppGini plugins to add more power to your apps:
- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.
Re: Auto Increment with Letter
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
DPA-SPD-GCPGHJ-0001-2015 (fixed string=DPA-SPD-GCPGHJ-, 0001= consecutive per year, 2015=actual year) every year initialize 0001