Re: Recursive Select Box
| From: | Jakes | Date: | Wed, 18 Feb 2004 09:55:23 +0000 |
| Subject: | Re: Recursive Select Box | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178084@lists.php.net to get a copy of this message | ||
use two loops 9(or as many as you need) with global varaibles. If a variable
in the top level loop is executed
it prints out the second loop. You need to do round trips to the db.
"Matt Palermo" <webmaster@sweetphp.com> wrote in message
news:20040218083536.96886.qmail@pb1.pair.com...
> Hey everyone. I'm looking for assistance/suggestions/answers on how to
> build a select dropdown box from data that needs to be pulled recursively
> from a MySQL database. Basically the situation is mainly for a dicussion
> thread system type of thing where I have categories nested inside
> categories, nested inside categories... Anyway, I want to be able to
build
> a drop down box containing all the categories indented underneath it's
> parent category to look something similar to this:
>
> -------------------------
> Top Level Category
> - Nested Category
> - Lower level
> - Etc....
> Top Level Category
> - Nested Category
> Top Level Category
> -------------------------
>
> Then the user will be able to select one from the dropdown menu. I have
all
> the categories stored in a MySQL database called site_categories. The
table
> is setup like this:
>
> __________________________________
> | Cat_ID | Cat_Parent | Cat_Name |
> |---------------------------------------------|
> | 1 | 0 | Top Level 1 |
> |---------------------------------------------|
> | 2 | 1 | Nested 1 |
> |---------------------------------------------|
> | 3 | 0 | Top Level 2 |
> |---------------------------------------------|
> | 4 | 2 | Nested 2 |
> |---------------------------------------------|
>
> Sorry for the bad pictures you hopefully you get the idea. Anything with
a
> 0 Cat_Parent is a Top Level category. Then the others are all nested
inside
> other categories that have the same Cat_ID as the nested categories
> Cat_Parent. I basically need help creating a properly indented dropdown
> menu box using this structure from the database. I assume I'm gonna have
to
> use some sort of recursion here, but I'm not sure how to go about this.
> Please help if you can.
>
> Thanks,
>
> Matt
> http://sweetphp.com