Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中自动增加值?_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

如何在php中自动增加值?

如何在php中自动增加值?,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我是php新手,当我在表中添加数据时,项目id将是自动递增,它必须从00000001开始我将使用什么php函数 item_Id | item_description 00000001| Samsung galaxy s3 当我添加另一项时,它将是这样的: item_Id | item_description 00000001| Samsung galaxy s3 00000002| Remote Controller 我用的是codeigniter 定义表时,在数据库中执行自动递增操作

我是php新手,当我在表中添加数据时,项目id将是自动递增,它必须从00000001开始我将使用什么php函数

item_Id | item_description
00000001| Samsung galaxy s3
当我添加另一项时,它将是这样的:

 item_Id | item_description
 00000001| Samsung galaxy s3
 00000002| Remote Controller

我用的是codeigniter

定义表时,在数据库中执行自动递增操作:

create table items (
    item_id unsigned not null auto_increment,
    . . .
);
插入项目时,只需插入
项目id
之外的所有其他列即可:

insert into items(col1, . . . )
    . . .
每当插入新值时,数据库会将
项目id
设置为新值

注意:插入的值是一个整数。如果要将其作为零填充字符串拉出,可以执行以下操作:

SELECT LPAD(item_id, 8, '0')

因为它是一个项目ID,不用于计算,所以只需使用VARCHAR并格式化数字,以添加前导零并转换为字符串

更多的是关于如何设置MySQL数据库,使用自动递增将
item\u Id
列设置为主键,如何设置以“00000001”开头的item\u Id?抱歉,我是PHP新手。这可能有助于设置自定义自动增量::也许您可以在我设置项目id时得到答案,它将是这样的?项目id未签名非空自动增量=“0000000 1”,?@Vincent。初始值为1,因此不需要设置它。而且,前导零是无用的,因为列是数字的。当你查询值时,你可以把它们放进去。但是我需要另外七个零,我会在我的其他html页面中显示它。这就是为什么我有“便条”。您可以使用
lpad()
将它与前导零一起拉出。如果仔细想想,就不能“递增”字符串值。但是,您可以递增一个数字并将其转换为字符串。@GordonLinoff我没有将ZEROFILL与PHP结合使用,但不会
item_id INT(8)UNSIGNED NOT NULL ZEROFILL AUTO_increment如何在PHP中将其捕获为填充值?编辑:哇,老线程。不确定这是如何/为什么在最近的问题上出现的。