Ihthishaam Fahim Ihthishaam Fahim - 1 month ago 9
MySQL Question

change values of Autoincrement ID on mysql using php

I want to change the values of the ID based on different categories on my product table on mysql

for an example-

tshirts will use an ID of TS00XXX

shorts will use an ID of SH00XXX

I am using a form to add the products to the table so that you can select different categories based on that.

i am using php and mysql, if someone can help me out with this.

thank youu

Answer

Best possible solution would be, Leave ID integer and Auto-Increment.

Create new field called "product_type" which either 'TS' ,'SH' or any other types you might have to store.

while retrieving you can always user concat function, in this case

select concat(product_type, id) as product_id, * where product_id = 'SHXXX'

returns product_id 'TSXXX' or 'SHXXX'

or get id by product

select * where product_type = 'SH' and id = XXX