select with parentID field into multidimensional array?
| From: | Stephen | Date: | Sun, 21 Jan 2001 12:49:13 +0000 |
| Subject: | select with parentID field into multidimensional array? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-6014@lists.php.net to get a copy of this message | ||
Hi
I have a table which is set out like this
ID name parentID
I "select * from table" into $result.
I then wish to walk through the result such that it creates a
multidimensional array sorted with children under parents. Here is a basic
eg.
ID name parentID
1 books 0
2 movies 0
3 songs 0
4 horror 1
5 love 1
6 horror 2
7 love 2
8 scifi 2
9 IT 4
etc
I am trying to write a function that would then insert these into a
multidimensional array as such...
$array[1] = "books";
$arary[1][4] = "horror";
$array[1][4][9] = "IT";
etc, so I could pull them out into a select dropdown list nicely sorted.
I am not sure how to write an array function with an unlimited number of
levels. If someone could help out it would be greatly appreciated.
Thanks
Stephen