Re: category structure
| From: | DL Neil | Date: | Mon, 29 Oct 2001 10:31:58 +0000 |
| Subject: | Re: category structure | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13797@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "olinux" <olnx@yahoo.com>
To: <php-db@lists.php.net>
Sent: 29 October 2001 08:16
Subject: [PHP-DB] category structure
> anyone have any ideas on this
>
> I have a table of directory categories
> id | parentid | category
>
> so...
> 1 | 0 | blah1 top
> 2 | 1 | blah2 sub
> 3 | 1 | blah3 sub2
> 4 | 3 | blah4 sub2->sub
>
> I want to hit the DB only once so i select all and
> drop into array
>
> Now i've created array with these like so:
> $category[$parentid][$id]
>
> But now what?
>
> trouble is that
> $msub[2][4] is a sub category of $msub[1][2]
> so i can't just run thru and print the array - need to
> manipulate a little.
>
> Any ideas? [or even a beeter way to do this?]
Olinux,
What you are asking is a fairly common requirement, with well-known solutions.
In what format do you require the output printed?
Do you know what a "tree" data structure is, and how to 'walk the tree'?
=dn