This topic is locked
[SOLVED]

 customer number in a edit field

10/13/2020 3:34:26 AM
PHPRunner General questions
J
Jan author

I generate a customer number with the code below
$rs = DB::Query("Select COUNT(name) as total from customers");

$number= $rs->value("total");

$number=$number + 1;
I want to write this customer number in an edit field
What code do I need for this? Thanks

K
kdgsv 10/13/2020

For your inspiration:
I'm using the following code @add page, before record added:

$sql="select max(substr(tbl_project_id,9)) as mx from tbl_project where substr(tbl_project_id,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="PR";

$str2=date("Ym");

$str3=($data["mx"]+1);

$values["tbl_project_id"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);
return true;


This code creates a number like shown below.
PR20200500002

Sergey Kornilov admin 10/13/2020

If you need to save this number to the database use BeforeAdd event like Matthias suggested.
If you need this number to be seen on the Add page use Process Record Values event of the Add page:

https://xlinesoft.com/phprunner/docs/process_record_values.htm

J
Jan author 10/14/2020

thanks for the valuable information !

R
ringlis1 10/29/2020

I have added this code to the event Before Record Added, however, it is not adding to the last number, I keep getting the same number. Any ideas?



$sql="select max(substr(VISNo,12,5)) as mx from VISInspection where substr(VISNo,8,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="SC-VIS-";

$str2=date("Ymd");

$str3=($data["mx"]+1);

$values["VISNo"]="$str$str2".str_pad($str3, 3, 0, STR_PAD_LEFT);

return true;
S
smez 10/30/2020

Try:
$values["VISNo"]= $str.$str2.str_pad($str3, 3, 0, STR_PAD_LEFT);