I wanna create a column in database that will increment the item code with prefix say IT with respect to the primary key (id). can anybody suggest easy way to do this? Thanks in advance
Asked
Active
Viewed 40 times
0
-
So prefix `IT` for every row? – nice_dev Feb 09 '20 at 08:01
-
yes. column name would be item_code and in every row item code should look like i.e IT0001, IT0002, IT0003 so on. – alphaCoder Feb 09 '20 at 08:06
-
i'm trying to do it in same table not with two tables. is there anyway to do it within same table? – alphaCoder Feb 09 '20 at 08:15
-
Well, instead of storing the prefix, why not attach it only while displaying? – nice_dev Feb 09 '20 at 08:19
-
You are right. I need to store this because when i'm generating barcodes i will retrieve it from db when searching for items and print their barcode labels. i'm doing this for first time so i could be wrong so i'm open to suggestions. – alphaCoder Feb 09 '20 at 08:23
-
Then just fetch the ID and generate the barcode by passing it into your function like `generate_barcode('IT'.$your_id);` – nice_dev Feb 09 '20 at 08:41
-
Store as less as possible in the database. Numbers are much way faster as IDs. Just prefix on display. – Markus Zeller Feb 09 '20 at 08:50