Re: Creating alphanumeric id for a table

From: Date: Fri, 11 Sep 2009 22:26:16 +0000
Subject: Re: Creating alphanumeric id for a table
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-297932@lists.php.net to get a copy of this message
aveev wrote:
where the id consists of 3 alphanumeric characters and 4 numerical digits in the beginning (for numerical digit, it can grow like this AAA10001). I try to use php script to generate id like this, where I use the following script. <?
    function generate_id($num) {
        $start_dig = 4;
        $num_dig = strlen($num);
            $id = $num;
        if($num_dig <= $start_dig) {
            $num_zero = $start_dig - $num_dig;
                    for($i=0;$i< $num_zero; $i++) {
                $id = '0' . $id;
            }
        }
        $id = 'AAA' . $id;
        return $id;
    }
You can create a stored procedure or a trigger on inserting that implement your id logic. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org Seeking for a position <http://lupusmic.org/pro/>

« previous php.general (#297932) next »