php - How to have a automatic id generation in view page? -


hi using codeigniter have view page simple form few information items purchased. item purchased needed saved in table same id. example

-+------+-----------+  +  id  + items     +  +------+-----------+  +  1   +  iphone6s +  +------+-----------+  +  1   +  ipad     +  +------+-----------+ 

here same id need generate bill , close view page. when purchase open next id must change 2 automatically. other purchased id until bill generation 2 , next 3 on.. how this? can me? please give me solution. in advance

you should have 2 tables.

a table, lets say, 'bills' keep track of bills.

a table, 'bills_items', bill's items.

'bills' should have pk autoincrementing generates new id each inserted record (a bil).

each time insert bill on can newly created id variable $idvar = created id mysql_insert_id(...)

then insert items of purchase in 'bills_items' using value of $idvar id

check http://php.net/manual/en/function.mysql-insert-id.php


Comments