What's an elegant way to set this up?
Posted: Fri Sep 18, 2009 3:32 pm
Hi all,
I've got basic PHP/MySQL knowledge, but can't really get my head wrapped around this...
There's this site, which features a photographer's portfolio. All his series are arranged in categories, but these can have subcategories too.
I want to create a multi-level dropdown menu reflecting the hierarchy in categories, and fill those categories with names of the actual series.
To give him complete flexibility, I set up the database like this:
A new category which should be assigned as a sub to an already existing one, simply puts uses that ID for parentID value.
Using 'position' he can arrange the categories and the subcategories.
Now, I'm stuck on two things, which basically boil down to the same question I think.
1) I want to output this data, hierarchically to an XML file (at least for the menu, so it doesn't have to perform a query each time)
2) The dropdown menu needs to reflect this hierarchy too.
I managed to retrieve the data in right order by using an 'ORDER BY category, position' clause, but really have no clue how to run through this array efficiently...
Any suggestions?
Thanks a million!
best regards,
I've got basic PHP/MySQL knowledge, but can't really get my head wrapped around this...
There's this site, which features a photographer's portfolio. All his series are arranged in categories, but these can have subcategories too.
I want to create a multi-level dropdown menu reflecting the hierarchy in categories, and fill those categories with names of the actual series.
To give him complete flexibility, I set up the database like this:
Code: Select all
Catogories table:
ID
name
parentID
position
Series table:
ID
category
...
Using 'position' he can arrange the categories and the subcategories.
Now, I'm stuck on two things, which basically boil down to the same question I think.
1) I want to output this data, hierarchically to an XML file (at least for the menu, so it doesn't have to perform a query each time)
2) The dropdown menu needs to reflect this hierarchy too.
I managed to retrieve the data in right order by using an 'ORDER BY category, position' clause, but really have no clue how to run through this array efficiently...
Any suggestions?
Thanks a million!
best regards,