What's an elegant way to set this up?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tvdhoff
Forum Newbie
Posts: 3
Joined: Fri Sep 18, 2009 3:04 pm

What's an elegant way to set this up?

Post by tvdhoff »

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:

Code: Select all

 
Catogories table:
ID
name
parentID
position
 
Series table:
ID
category
...
 
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,
Post Reply