Auto Increment with Letter

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Auto Increment with Letter

Post by AhmedBR » 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
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Auto Increment with Letter

Post by AhmedBR » 2013-09-19 10:37

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

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Auto Increment with Letter

Post by a.gneady » 2013-10-14 01:21

Thanks for sharing, Ahmed.
:idea: 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.

clar1970
Posts: 7
Joined: 2015-02-15 03:24

Re: Auto Increment with Letter

Post by clar1970 » 2015-02-17 19:17

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

Post Reply