Microsoft
Software
Hardware
Network
Question : Storing catagories and sub categories in a database
Hi,
Im planning a website which will contain lots of items all in different categories. I know how to store different categories all with their own unique ID. But im trying to work out how to store the sub categories so I can tell which ones belong to which category. If the sub categories have their own unique ID there will be nothing saying which category they are in. So all I can think of is, if I have a category ID of 1, having sub category ID's of 1.1, 1.2, 1.3 and so on.
Look at this example. If I had a category called "PC Components" with an ID of "22". Inside that there is "Graphics Cards" with and ID of "22.1". Then inside that there are "AGP 8x" with an ID of "22.1.1" and "PCI Express" with an ID of "22.1.2".
(22) PC Components
(22.1) Graphics Cards
(22.1.1) AGP 8x
(22.1.2) PCI Express
As far as im aware no number fields will accept more than one decimal point. So the only way I can see to do this is to use a string to store the ID's and then split the string to obtain the seperate ID's. However, I cant remember if your able to set a string as a primary key field.
So my question is how can I do this?
(Just encase it affects anything, I will be using PHP with MySQL)
Thanks in advance
mms_master
Answer : Storing catagories and sub categories in a database
Try to have 3 basic fields:
1. Id
2. ParentID
3. Decription
You can create any "tree" using this schema
Any item can have as many sub-items as you like and all of them will have unique ID withing the same parent, etc....
Random Solutions
Photoshop change color
exchange 2003 email address show x400 or x500 information
IsDefined problem
Get Param from File not via post get method
SMB over VPN Troubles
Exchange Defrag and Windows Defragmenter?
Cannot manage remote computer
Change Sort Order from 49 to 52
MS-SQL 2000 LOCK_TIMEOUT
not connecting to computer mapped as network drive