0

Insert record in php and MySQL and generate id based on that.

I want to insert a record in php and then generate an ID based on that. for instance if I insert "shyam" as name and my id is 1 in the table which is primary key. once my record is inserted an Id should be generated like shy001. if name is Vikas and id is 2 then id should be vik002.

30th Jan 2017, 10:48 AM
Shyam Dhuriya
Shyam Dhuriya - avatar
1 Answer
0
$zeros = ""; if (mysql_insert_id () <10) { $zeros = "00"; } else if (mysql_insert_id () <100) { $zeros = "0"; } $id = $substr($var,1,3).$zeros.mysql_insert_id ();
8th Feb 2017, 11:27 AM
Radchenko Vitalii
Radchenko Vitalii - avatar