Short description of hierarchical data model AKA parent-child relationship can be found in description of GetAnyBaby custom tag. This function supplements the above referred custom tag. It draws all parent levels up from selected point within table of hierarchical structure. Say to reflect path of parent subcategories on selected product's page, for example:
| Category: | Web »» Web Development and Design »» Coldfusion |
Gold text above is produced by this function.
To accomplish this task, first we need to run recursive GetAnyParent custom tag similar to GetAnyBaby custom tag already mentioned before. GetAnyParent script finds all hierarchical branches above currently selected one and records their IDs into parentids field of the table. Like a string list of IDs, for example as the following:
"768,56,4,1"
Arguments to be passed into GetAnyParents tag are:
| branchid | - parent branch id | | table | - parent-child table name | | idfield | - name of the field-UID (primary key) | | namefield | - name of the char name value field (source of string value data) | | subidfield | - name of the field which points to the parent branch | | | | It returns: | | idparentlist | - list of IDs | | nameparentlist | - list of names | | levelparentlist | - nesting levels list | We only will use idparentlist for CategoryPathUp function.
So our hierarchical parent-child table named "webdevelopment":
| CATEGORY | CATEGORYID | SUBCATOFID | PARENTIDS | | Web | 15 | 0 | - to be found - | | Web Development and Design | 16 | 15 | - to be found - | | Coldfusion | 17 | 16 | - to be found - | | PHP | 18 | 16 | - to be found - | | ASP.net | 19 | 16 | - to be found - |
Example of GetAnyParent custom tag call to find all parent IDs for the "Coldfusion" category is:
<CF_GETANYPARENT table="webdevelopment" namefield="category" idfield="categoryid" subidfield="subcatofid" branchid="17" >
Which returns list of parent IDs, for example : 15,16
And then we run query to update parentids fields in our table, for instance:
<CFQUERY datasource="#REQUEST.ds#" > update webdevelopment set parentids='#idparentlist#' where categoryid=17 </CFQUERY>
On the second and the last step we call CategoryPahUp function to display parent categories with a single quick SQL query. Example for the table used above may look like this:
<cfscript> CategoryPathUp(table="webdevelopment", categoryid=17, link="dosomething.cfm");</cfscript> |