Jump to content

Category Tree


End User

Recommended Posts

I think someone may have posted a similar question not long ago, but this might be a bit different. I'm looking for some category management code that will work with an arbitrary number of categories and subcategories, to any reasonable depth. I've found a few so far (see below), but I'm wondering if anyone has any other suggestions, something they've used and would recommend? I've found quite a few examples of category tree code that are inefficient and rack up a large number of queries needlessly as they recursively build the tree, so I'm hoping to find something that's efficient or "thrifty" if you will. I found this page that has an example that seems to fit the bill, but there's no clear example given:http://bytes.com/topic/php/answers/2336-me...s-subcategories (scroll down a bit)Takes just one query and then it hands the dirty work off to PHP. This is what I'd like to do, but looking at what's there doesn't quite clue me in. Here's a category class that also seems promising:http://www.phpclasses.org/package/2415-PHP...s-database.htmlSo...any suggestions or code snippets to share?

Link to comment
Share on other sites

If you really need arbitrary levels, you should probably consider using tags instead. You know, where a certain thing is part of one or more tags, and you can filter stuff based on if it has or hasn't a certain tag.The DB structure to implement it is relatively easy to construct and work with. You have one table for tags (with tag ID and the actual tag), a table with the "stuff" that the tags apply to (ID and all), and a third table with two primary keys (and nothing more) - the ID of the thing, and the tag ID.

Link to comment
Share on other sites

Display only, meaning this is just to view the categories, not manage them?
Yes, just to display them, probably in a tabled "drill-down" format (or in a dropdown box). I just need the category generation code, I can write the back-end stuff to manage the categories (add, edit, delete).
Link to comment
Share on other sites

Assuming the number of categories, including necessary HTML is within the bounds of an acceptable page size (meaning <60K?), what about using a cron job to write the HTML into a static file, which uses simple DIV/ul/li/hide/toggle to display the categories and drill down. The page content can be delivered either using AJAX or by reloading the page. If you used a SELECT statement with ORDER BY `parent_category`,`category` and then a loop through the resulting data, it might work.The page could be .shtml or .php - including the static HTML.Although the initial page load would have extra content, navigation through the categories would be entirely client-side, and content delivery would be limited to only the requested content, also, you could use the title tag to create a breadcrumb navigation path at the top of the page.If you post or PM the schema - I'll think on it a bit more ...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...