Re: Creating alphanumeric id for a table
| From: | Jo�o C�ndido de Souza Neto | Date: | Fri, 11 Sep 2009 19:30:22 +0000 |
| Subject: | Re: Creating alphanumeric id for a table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297924@lists.php.net to get a copy of this message | ||
I don´t know if it´d be the right way, but what about using trigger in this
case?
"aveev" <nashrullah_anas@yahoo.com> escreveu na mensagem
news:25391939.post@talk.nabble.com...
>
> I want to create user generated id like this :
> AAA0001
> AAA0002
> ...
> AAA0009
> AAA0010
>
> 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;
> }
>
> $app_id = generate_id(1);
>
> ?>
>
> I assume that I can get increment value/sequence from db (I used harcoded
> increment value in the code above (generate_id(1))),
> but I don't know how I can get this incremental value from db.I use mysql
> 5.0.
> Or has anyone had another solution to create this alphanumeric id ?
>
> Any help would be much appreciated
> Thanks
> --
> View this message in context:
>
> http://www.nabble.com/Creating-alphanumeric-id-for-a-table-tp25391939p25391939.html*
7éÁ½úÈ
> âß§Óì
> Sent from the PHP - General mailing list archive at Nabble.com.
>
>