FooKelvin Posted October 7, 2015 Share Posted October 7, 2015 Hi, how to generate auto increment ID with combination of characters and number. For example, i would like to have product ID start from PROD00001. When i add second product, the ID will check on the existing database to check PROD00001 is the latest ID. So, the second product ID will +1, become PROD00002. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 7, 2015 Share Posted October 7, 2015 So what exactly prevents you from using an actual AUTO_INCREMENT column? This “PROD...” stuff is only how you would display the numeric ID, and it can easily be done using (s)printf(): <?php $id = 5; printf('The ID is PROD%05d', $id); In any case, don't try to invent your own auto-increment mechanism. If you naively select the latest ID, increment it and then update the ID, you'll get duplicate IDs when two PHP processes run at almost the same time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.