To be destructive, I would use a sensible data-representation in mysql,
yours seems to suck...
something like
table x
idx as integer, auto_increment, primary key
node as text
parent as int (this points to the parent primary key)
But here is what I would do with the current data structure (recursive
stuff):
get all nodes of the current level (starting with 1): select distinct
parent_cat from <table> where level = <the current level>
this gives you all nodes...
now with each node do: select child_cat from <table> where level = <the
current level> and parent_cat = <the current parent node>
this gives you all children...
then increase the level and redo from start...
it is possible to wrap all that up in a query, but the handling would be
much worse and since neither the amount of levels nor the uniqueness of the
nodenames is given, that could turn out to be rather nasty.
hope this helps a little...
remo
> I want to create an array like this:
>
> $tree = array (
> "first" => array ("stuff1", "stuff2", "stuff3"),
> "second" => array ("stuff1", "stuff2")
> );
>
>
> based on tree of information, stored in a database table:
>
> level parent_cat child_cat
> --------------------------
> 1 first first
> 1 second second
> 2 first stuff1
> 2 first stuff2
> 2 first stuff3
> 2 second stuff1
> 2 second stuff2
>
>
> That translates to a structure like this:
>
>
> first second
> | |
> |---------|--------| |-----------|
> stuff1 stuff2 stuff3 stuff1 stuff2
>
>
> Can someone point me towards an SQL example that would help me
> structure the
> query, and an example of how to reference information in it once
> I have it?
> e.g. a while list/each but for a multidimensional array?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]