0

我想自动增加字母数字字符例如:amp001,amp002,amp003 谁能帮我解决这个问题。

我应该得到像

id
abc001
abc002
abc003
abc004
..
..
..
4

3 回答 3

2

You can't auto increment alphanumeric values. Just Change the field type to numeric and set auto increment to that field. Concate your string value before the ID, while fetching the value. Eg: <?php echo "abc".$row['id']; ?>

于 2013-08-29T09:02:50.223 回答
0

If you really want this, use php's uniqid function.

于 2013-08-29T09:06:30.350 回答
0

看这个例子

//connect to you database
//$count = mysql_query("select count(*) from table_name");
$id = "abc";
if (strlen($count+1) < 4)
{
    $count++;
    for($i=0;$i<(3 - strlen($count));$i++)
    {
        $id .='0';
    }
    $id .= $count;
}
于 2013-08-29T09:27:19.780 回答