How to automatically increment value in php?

I am new to php and when I add data to my table, item_id will be AUTO INCREMENT and it should start with 00000001 , what php function will I use?

item_Id | item_description
00000001| Samsung galaxy s3

and when I add another element, it will be something like this:

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

I am using codeigniter.

+4
source share
2 answers

You automatically increase the number in the database when you define the table:

create table items (
    item_id unsigned not null auto_increment,
    . . .
);

When you insert an element, just insert all other columns except item_id:

insert into items(col1, . . . )
    . . .

The database will set the value item_idto the new value when new values ​​are inserted.

: . , :

SELECT LPAD(item_id, 8, '0')
+3

Source: https://habr.com/ru/post/1532074/


All Articles