icloudJunction icloudJunction - 2 years ago 63
PHP Question

Need help while generating reference no using php and Mysql

My code is:

$regno = 'B'.date('Ymd');

for generating reference no. for registered user.
if 2 user is registered on July 15, 2016. and 3 user is registered on next day then
I want to generate ref, No.

for 1st day

B201607151 for 1st user

B201607152 for 2nd user

2nd day

B201607161 for 1st user

B201607162 for 2nd user

B201607163 for 3rd user

So what kind of changes i should make in my code.
Please advise.


Thank you for your suggestion. My issue has been solved.

Answer Source

First, you get the last reference, you put it for example in $last_ref, Then you get the last sequential of the current day, then you increment that sequential, try this :

$regno = 'B'.date('Ymd');
if($last_ref) // check if there is a reference in the current day
    $sequential = str_replace($regno,'',$last_ref);
    $new_reference = $regno.($sequential+1);
else $new_reference = $regno.'1';

I hope that will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download