Jump to content


Photo

product ids


  • Please log in to reply
8 replies to this topic

#1 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 14 August 2006 - 11:32 PM

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 August 2006 - 11:41 PM

but different categories will be in different tables in the database


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.

#3 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 14 August 2006 - 11:45 PM

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?

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 14 August 2006 - 11:52 PM

Have another column for category. Auto-increment is designed for ID columns, you should just let it do its job.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 14 August 2006 - 11:54 PM

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

#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 August 2006 - 11:55 PM

is there a better way?


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

CREATE TABLE products (
  id INT PRIMARY KEY,
  title VARCHAR(80),
  cat INT
)

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

SELECT * FROM products GROUP by cat


#7 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 14 August 2006 - 11:57 PM

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


Well, how are you defining your categories?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#8 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 15 August 2006 - 12:06 AM

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.



#9 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 15 August 2006 - 12:17 AM

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.

CREATE TABLE category (
  id VARCHAR(80) PRIMARY KEY,
  title VARCHAR(80),
 )

Or something like that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users