Jump to content

product ids


Nothadoth

Recommended Posts

im trying to put product ids on my website for my sales. but different categories will be in different tables in the database. if in each one it is a id that goes 1,2,3 etc. they will clash. So i was thinking maybe an auto-increment that would go 1,2,3 etc. but have letters at the beggining or end to show what category it is in: eg. P1, P2 and F1, F2. Is this possible? or does anyone know an affective way of doing product ids?

Thanks
Link to comment
https://forums.phpfreaks.com/topic/17568-product-ids/
Share on other sites

[quote]is there a better way?[/quote]

Yes. Database normalization. At its simplest you would have a signle table something like...

[code]
CREATE TABLE products (
  id INT PRIMARY KEY,
  title VARCHAR(80),
  cat INT
)
[/code]

This enables you to store all your products in a single table, all with a unique id, and all in there own catigories if required. To get the all products, you would simply query something like....

[code]
SELECT * FROM products GROUP by cat
[/code]
Link to comment
https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74826
Share on other sites

Just like anything else, your categories need an ID. It could be like:

PC
Printers
Keyboards
Monitors

or like:

CAT1
CAT2
CAT3

or like:

1
2
3

etc.


In most shopping carts there's a separate table for category creation containing those ID's. Then, in your product table, you'd have a field for category and reference the proper category ID in that in order to assign the product to the right category. Your while loop would run through the product database and display the products as per category.

[code]CREATE TABLE category (
  id VARCHAR(80) PRIMARY KEY,
  title VARCHAR(80),
)[/code]

Or something like that.
Link to comment
https://forums.phpfreaks.com/topic/17568-product-ids/#findComment-74844
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.