Re: Repeated Parenting Queries

From: Date: Mon, 02 Oct 2000 03:43:53 +0000
Subject: Re: Repeated Parenting Queries
Groups: php.general 
Request: Send a blank email to php-general+get-18240@lists.php.net to get a copy of this message
Addressed to: "Waldo L. Jaquith" <waldo@waldo.net> php-general@lists.php.net ** Reply to note from "Waldo L. Jaquith" <waldo@waldo.net> Sun, 1 Oct 2000 12:28:34 -0400 (EDT) > 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? I can only think of one other way to do this. Grab the whole table and load the parent info into an array. This is not a very good solution if there are many entries. For a small number of entries it might be faster than doing a query in a loop. On the other hand, the big time expense in most database programs is connecting to the database. Once the connection is made multiple queries don't take all that long. If your database uses some kind of cache, you might be suprised how fast you get the data back. When in doubt... benchmark. Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#18240) next »