This topic is locked

ID generate concatenate-current-date-autonumber

10/16/2017 3:47:06 AM
PHPRunner General questions
K
Khampol author

Hi,
I would like to generate auto id depends on Year month and day :
20171016001

20171016002

20171016003

....

20171016012

20171016013

.....
this topic is perfect but to problem is the last code I cannot manage to make it work with my phpRunner <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=25085&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />(
http://asprunner.com/forums/topic/14682-concatenate-current-date-autonumber/

HJB 10/16/2017

Citing excerpt ex: http://asprunner.com/forums/topic/14682-concatenate-current-date-autonumber/
I found the solution now : <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83480&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
The code below will concat CUSTOM STRING + CURRENT YEAR + CURRENT MONTH + SEQUENCE NUMBER to produce transaction number

The Sequence number will always start from 00001 when start each month.
Sample for transaction in month June :

SO20100600001

SO20100600002

SO20100600003

............

SO20100600011

SO20100600012
Sample for transaction in month July :

SO20100700001

SO20100700002

SO20100700003

............

SO20100700011

SO20100700012
The code is :
$sql="select max(substr(PURCHASE_NUMBER,9)) as mx from TABLENAME where substr(PURCHASE_NUMBER,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="SO";

$str2=date("Ym");

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

$values["PURCHASE_NUMBER"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);
where SO is my custom string. you can replace it with your own...

K
Khampol author 10/16/2017

I found the solution now : <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83482&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />



Yes, I red that too.
Here my problem :
If I use this :

$sql="select max(substr(PURCHASE_NUMBER,9)) as mx from TableName where substr(PURCHASE_NUMBER,5,2)=month(now())";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str=date("Ymd");

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

$values["PURCHASE_NUMBER"]=$str;


This is ok and I got this :


If I use this code :
$sql="select max(substr(PURCHASE_NUMBER,9)) as mx from TABLENAME where substr(PURCHASE_NUMBER,7,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="SO";

$str2=date("Ym");

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

$values["PURCHASE_NUMBER"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);
I get this :


!!??

And if i want to add more.. I got this


<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83482&image=5&table=forumreplies' class='bbc_emoticon' alt=':unsure:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83482&image=6&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />
Better ideas please ?....

K
Khampol author 10/16/2017

Am I correct for the DB ?

K
Khampol author 10/16/2017