Jump to content

Archived

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

Nothadoth

product ids

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
because if they are in different categories i can use a while loop to display all of the categories on a page. is there a better way?

Share this post


Link to post
Share on other sites
Have another column for category. Auto-increment is designed for ID columns, you should just let it do its job.

Share this post


Link to post
Share on other sites
how would i use a while loop to display links to all categories if it has a column with it in? i thought of it before

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[quote author=Nothadoth link=topic=104275.msg415834#msg415834 date=1155599652]
how would i use a while loop to display links to all categories if it has a column with it in? i thought of it before
[/quote]

Well, how are you defining your categories?

Share this post


Link to post
Share on other sites
i would have a field called Category

and it would say like "PC" or "Printers" in it.

I need a page where it will display links to all the different categories so you can click it to show all items under that category.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.