Soldato
- Joined
- 24 Nov 2002
- Posts
- 16,378
- Location
- 38.744281°N 104.846806°W
I have a mysql table that contains parent|child. Just two columns and 800 rows.
I'd like to extrapolate a familial relation from this list. And wrote something in PHP to do this, however it is VERY inefficient. There can be up to 8 or 9 levels on the hierachy in places, in others just 2. I was writing it in a case-by-case way... but proved too long and inefficient!
There must be an easy way to iterate up and down the list to use:
food|cheese
drink|wine
drink|beer
drink|soda
wine|red
wine|white
beer|lager
beer|bitter
beer|ale
to produce, for example if I searched for lager:
drink
note food and cheese wasn't called.
I'd like to extrapolate a familial relation from this list. And wrote something in PHP to do this, however it is VERY inefficient. There can be up to 8 or 9 levels on the hierachy in places, in others just 2. I was writing it in a case-by-case way... but proved too long and inefficient!
There must be an easy way to iterate up and down the list to use:
food|cheese
drink|wine
drink|beer
drink|soda
wine|red
wine|white
beer|lager
beer|bitter
beer|ale
to produce, for example if I searched for lager:
drink
beer
lager
bitter
ale
soda
wine
red
white
note food and cheese wasn't called.
Last edited: