Jump to content


Photo

**SOLVED** Sub-Category Indenting


  • Please log in to reply
4 replies to this topic

#1 FrostiE

FrostiE
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 11 March 2006 - 11:56 AM

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 March 2006 - 12:18 PM

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]?
Legend has it that reading the manual never killed anyone.
My site

#3 FrostiE

FrostiE
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 11 March 2006 - 12:50 PM

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.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 11 March 2006 - 01:18 PM

try

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>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 FrostiE

FrostiE
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 11 March 2006 - 01:41 PM

Thanks so much. works perfectly !!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users