Re: category and sub category traversal

From: Date: Tue, 02 Dec 2008 10:01:23 +0000
Subject: Re: category and sub category traversal
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-283984@lists.php.net to get a copy of this message
> I need some help in figuring out this logic. > > I have two tables one for category and other for category_hierarchy. > category_hirerarchy has a column to determine the parent. > > So the query I have to retrieve tree of one specific category is: > > SELECT t.tid, t.*, parent FROM term_data t INNER JOIN term_hierarchy h ON > t.tid = h.tid WHERE t.vid = 16 ORDER BY weight, name; > > The ones with parent = 0 is the top category > > Now I need to prepare an associative array with parent child relation. > > So bascially I need to retrieve [parentID] => array('childID', > 'chidName') > > Can anyone shed some light on the logic involved in preparation of this > array with out using multiple sql queries? The structure you've highlighted is very common (that's not to say bad at all). You might be interested in this: http://www.phpguru.org/downloads/Tree_array/Tree.phps Which looks at the same structure and creates a tree object from it. Using this you will be able to manage it. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org (Updated November 29th)

« previous php.general (#283984) next »