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
Microsoft Vista Will Not Open "Manage Network Connections"
How to get SQL statement for a trigger in ORACLE v10.2 database
Windows Mail will not shut down
How to drop the BUILTIN\Administrators login
Determine what Sybase Database ports are available to use
DNS Lookup Failed
How to manually remove an Exchange Server that was not uninstalled.
Installing OCX (EasyInk) for IE Mobile on Windows Mobile 5 PDS
syntax for Win32::Ole xml POST using MSXML 4 core services
Running Java applets on specific websites domain windows 2003 ent edition