[nycphp-talk] Logic Help
Jeff Loiselle
jeff.loiselle at gmail.com
Thu Oct 27 12:12:25 EDT 2005
Hello,
I will submit that am really just not smart enough to figure this out.
My logic sucks. Why am I a programmer? I don't know. Someone must have
drugged me the day I picked my career. But I have records in a
database that look like this..
array(
'id',
'name' ,
'parent_id'
)
I want to build a tree.
So far I have..
while ($record->fetch()) {
$tree[$record->parent_id][$record->id] = $record->name;
}
That produces something like this.
Array
(
[] => Array
(
[1] => General
)
[1] => Array
(
[2] => Diseases
[5] => Technologies
[6] => Financial Data
)
[2] => Array
(
[3] => Eg 1
[4] => Eg 2
)
[6] => Array
(
[7] => Articles
[8] => Models
[9] => Comps
)
)
Now how can I go about appending each node to its matching parent? Or
is there a completely better way?
Have I made any sense? ;-)
---
Jeff Loiselle
Web Developer, Musician, and Observer
http://jeff.loiselles.com
More information about the talk
mailing list