[PHP] Random Registeration number input
As the title says i want an Input like registeration number
which generates a alphanumeric 4 or 5 digit number like "ON200" or some thing like that
also a function to check if that id is there or not
if it exists it shld generate the next number like "ON201"
i have a normal registeration page. and databse mysql.
Thank you
Re: [PHP] Random Registeration number input
Try using something like this:
Code:
mt_rand(1000,5000);
Re: [PHP] Random Registeration number input
PHP Code:
function generateAccount ($length = 8)
{
$account = "";
$possible = "0123456789abcdfghjkmnpqrstvwxyz";
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
if (!strstr($account, $char)) {
$account .= $char;
$i++;
}
}
return $account;;
}
Re: [PHP] Random Registeration number input
What's wrong with auto-increment in SQL? or are you not using a form of SQL?
If not, then you can just make a function that takes the last number from an array and adds 1 to it..
PHP Code:
function next_increment($n)
{
$i = $n[count($n)];
$i++;
return $i;
}
$ID = Array (0,1,2,3,4,5,6,7);
$ID[] = next_increment($ID); //Add new ID..