Generating a menu
Posted: Tue May 21, 2002 1:11 pm
I'm working on a model store website and I want to generate a quick link menu sidebar. This side bar would allow access to different products easily. Since all the product information is stored in the database, it makes sense to do this dynamically
.
I have two main tables: product and productdetail. Product stores the company's info that makes the product. For example, "ID=1,name=Dragon". Productdetail stores the individual products as well as the product sub categories. ie
These are the table definitions:
Product(ID,title,URLpicture)
Productdetail(ID,productID,parentID,code,description,URLpicture)
The individual products are linked to a higher detail level via the parentID field. The parentID field references an ID of a row in the same table. ie
Productdetail(10,2,8,78001,Medic,78001.jpg)
Productdetail(10,2,8,78000,Police officer,78000.jpg)
Productdetail(9,2,8,minis,Mini figures,minis.jpg)
Productdetail(8,2,NULL,figures,Action Figures,figures.jpg)
So in this case, the first two rows are detail levels of the third row. And the third row is a detail level of the last one.
What would be a good way to represent this relationship in PHP?
I've tried various recursive functions, but they don't seem to capture the relationship completely. For example, the function won't work on an arbitrarily deep product detail level.
Thanks!
I have two main tables: product and productdetail. Product stores the company's info that makes the product. For example, "ID=1,name=Dragon". Productdetail stores the individual products as well as the product sub categories. ie
- Action Figures
- Minis
- 78000
78001
78002
1/6 scale - 78000
- Minis
These are the table definitions:
Product(ID,title,URLpicture)
Productdetail(ID,productID,parentID,code,description,URLpicture)
The individual products are linked to a higher detail level via the parentID field. The parentID field references an ID of a row in the same table. ie
Productdetail(10,2,8,78001,Medic,78001.jpg)
Productdetail(10,2,8,78000,Police officer,78000.jpg)
Productdetail(9,2,8,minis,Mini figures,minis.jpg)
Productdetail(8,2,NULL,figures,Action Figures,figures.jpg)
So in this case, the first two rows are detail levels of the third row. And the third row is a detail level of the last one.
What would be a good way to represent this relationship in PHP?
I've tried various recursive functions, but they don't seem to capture the relationship completely. For example, the function won't work on an arbitrarily deep product detail level.
Thanks!