Repeated Parenting Queries
| From: | Waldo L. Jaquith | Date: | Sun, 01 Oct 2000 16:28:34 +0000 |
| Subject: | Repeated Parenting Queries | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18211@lists.php.net to get a copy of this message | ||
Folks,
For a site of mine, I've made an ODP-like <http://dmoz.org>
interface,
that is actually pretty much identical to the ODP. Once I'm done, I'll
open source it, I guess.
The problem that I'm having is determining the parents of each level of
abstraction. To consider an example from the ODP, we have this category:
Top: Sports: Olympics: Summer Games: Sydney 2000: News and Media
If somebody goes to the "News and Media" page, there are 5 lookups to the
category-parenting system, to determine each parent until hitting category
1, "Top," at which point that it stops.
I'm currently looping a MySQL query in order to gather this data (query
the DB, add the result to an array, if category_id != 1, loop), but it
seems grossly inefficient. I've set up caching, so it only checks each
category once every 12 hours, but that's hardly a fix for poor code on my
part.
My question is this: Is there a single query, or a tighter loop, that I
could use to make this a little cleaner? This current setup really sucks,
and it's the only reason that I haven't launched the site yet. I'm
worried somebody may find out about my lame parenting query. :) Any
suggestions?
TIA,
Waldo