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
Share on other sites

[quote]but different categories will be in different tables in the database[/quote]

There is you problem. Why are different categories going into different tables? If product id's need to be unique, they really aught to be. Maybe you should look into database normalization techniques.
Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.