This topic is locked

Running Number

6/21/2016 12:49:57 AM
PHPRunner General questions
J
jefflau author

I would like to male running number on my project, the sample running number is PP160616-0001. PP is the location code. 160616 is year/month/date is mean 2016 year June and dated 16.
Lastly 0001 us the number of ticket on that day. Is that anyone able to help me on this

K
KelvinChua 6/21/2016



I would like to male running number on my project, the sample running number is PP160616-0001. PP is the location code. 160616 is year/month/date is mean 2016 year June and dated 16.
Lastly 0001 us the number of ticket on that day. Is that anyone able to help me on this


What type of database are you using?
Thanks.
Kelvin Chua

SINGAPORE

Sergey Kornilov admin 6/21/2016

Add this code BeforeAdd event of the table in question and make sure to use correct table and field names.

$table = "shippers";

$field="CompanyName";

$sql="select max(substr($field,10)) as mx from $table where substr($field,5,2)=month(now()) and substr($field,7,2)=day(now()) order by mx";

$rs=CustomQuery($sql);

if ($data=db_fetch_array($rs)) {

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

} else {

$str3="1";

}

$str="PP";

$str2=date("ymd");
$values[$field]="$str$str2-".str_pad($str3, 4, 0, STR_PAD_LEFT);

return true;