Auto-generated string structure

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Laim71
User
Posts: 75

Auto-generated string structure

Post by Laim71 »

Hi,

Can someone who has a working code help me.

I'd like to auto-generate a user submitted tickets codes.

The structure I want is DI-0001...n.

"DI-" is the constant part; "000x" wil grow incrementing by one unit according the last number used.

The field which contains the number is named "N°DI"

The field which contains the generated code is named "CodeDI"

THANKS


arbei
User
Posts: 9370

Post by arbei »

To create the default value of the ticket code with below steps.

  1. Get the max from the field "N°DI" with ew_ExecuteScalar().
    e.g.
    $maxid = ew_ExecuteScalar("SELECT MAX(<Field>) FROM <TABLE>");

  2. Calculate the new ID
    e.g.
    $newid = maxid + 1;

  3. Construct the ticket code using str_pad() PHP function then use it as the default value in Row_Rendered Server Event.
    For example:
    if (CurrentPageID() == "add")
    $this-><Field>->EditValue = <New Code>;

Read help file topic: "Server Events and Client Scripts" -> "Some Global Functions" for more information.


Laim71
User
Posts: 75

Post by Laim71 »

Hi,
This is my last code In Page Render event

$bcode="000";
$maxid = ew_ExecuteScalar("SELECT MAX("IDDI") FROM t_di");
$newid = $maxid + 1;
$code=str_pad("$bcode", 4, $newid, STR_PAD_RIGHT);

1 - Is it the right place to ru it?
2 - Could you check my logic.

THANKS


Webmaster
User
Posts: 9427

Post by Webmaster »

... in Row_Rendered Server Event.
For example:
if (CurrentPageID() == "add")
$this-><Field>->EditValue = <New Code>;


Laim71
User
Posts: 75

Post by Laim71 »

THANKS
IT works now.

I put the code generating function in global Code then called the function from Default value tag of the field.

Best Regards


Post Reply