Jump to content

Archived

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

FrostiE

**SOLVED** Sub-Category Indenting

Recommended Posts

Hey, was wondering if someone could help me. Basically I am creating a gallery script with infinite subcategories. The only problem I have is this:

For adding images, you have to select a category in the admin menu right? I want those categories to be aranged with all of a categories childeren underneath it. Something like this [img src=\"http://img224.imageshack.us/img224/3571/indent7am.jpg\" border=\"0\" alt=\"IPB Image\" /]

If someone could help me with the code I would be REALLY grateful!!!
Thanks

Share this post


Link to post
Share on other sites
Code? To do what, exactly? Have you looked at using the standard html [a href=\"http://www.w3schools.com/tags/tag_optgroup.asp\" target=\"_blank\"]optgroup tag[/a]?

Share this post


Link to post
Share on other sites
Well, basically I need to know how to retrieve all of the childeren under a category, not just the imediate ones, but childeren of childeren. Look at this image, it shows what I mean better:
[img src=\"http://img58.imageshack.us/img58/6228/indent8gy.jpg\" border=\"0\" alt=\"IPB Image\" /]

Obviously the ID depends on what order they where created as its auto_increment.

Share this post


Link to post
Share on other sites
try

[code]function listSubcats ($parent, $level=0) {
         $res = mysql_query ("SELECT category_id, name FROM categories
                              WHERE parent = '$parent'
                              ORDER BY name");
         while (list($id, $name) = mysql_fetch_row($res)) {
                $indent = str_repeat('>', $level);
                echo "<OPTION value='$id'>$indent $name</OPTION>\n";
                listSubcats($id, $level+1);
         }
}

echo "<SELECT name='cat'>";
listSubcats(0);
echo '</SELECT>';[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.