Jump to content

**SOLVED** Sub-Category Indenting


FrostiE

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
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.