|
Posted by Ivαn Sαnchez Ortega on 03/11/07 03:54
aaron@deloachcorp.com wrote:
> I have an array of id=>category:
>
> [018821] => Automotive Parts
[...]
> What I'm trying to do is loop through the array and create a category
> tree:
>
> Automotive Parts
> Domestic
> Foreign
[...]
> Any guidance?
Get the position of the last slash in the array value, run a in_array(), get
the parent ID...
That is pretty inefficient, so once you got the information about the parnt
of each node, store it in the DB (I suppose you're using a DB backend).
When fetching from the DB, rebuild the tree (remember you can use nested
arrays as trees), and everything will be much easier from there.
--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Beware of low-flying butterflies.
Navigation:
[Reply to this message]
|