Generate Random Number in PHP


function refrence_id()
{
    $refrence_id = 'DD'.mt_rand(100000, 999999);
    // check if number already exists in database
    $ref = mysql_query("select count(*) from registration where refrence_id='".$refrence_id."'");
    $refer_no = mysql_fetch_array($ref);
    if($refer_no[0] > 0)
    {
        refrence_id();
    }
    return $refrence_id;
}

$tmpRefID = refrence_id();

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.