I'm not sure how many levels of recursion your trying to do, but with CF 
there is a limit to recursion.  This little factorial function will show 
you that limit in a hurry if you put in a large enough value.

<cffunction name="factorial" access="public" returntype="numeric" 
output="yes">
    <cfargument name="end_value" required="Yes" type="numeric">
    <cfif end_value lte 1>
        <cfreturn 1>
    <cfelse>
        Calling myself with #arguments.end_value-1#<br>
        <cfreturn end_value * Factorial(arguments.end_value-1)>
    </cfif>
</cffunction>


<cfoutput>#factorial(1000)#</cfoutput>


Wil Genovese

One man with courage makes a majority.
-Andrew Jackson

A fine is a tax for doing wrong. A tax is a fine for doing well. 



Mike | NZSolutions Ltd wrote:
> Hi guys,
>
> I am attempting to create a limitless level category system.
>
> This is what I have so far...
>
> Calling page...
>
> <cfoutput>
> #application.category.display_categories(0)#
> </cfoutput>
>
> Cfc...
>
> <cffunction name="get_categories" output="false" access="public"
> returntype="query">
>               <cfargument name="parent_id" type="numeric" required="no">
>               <cfargument name="cat_id" type="numeric" required="no">
>       
>               <cfquery name="getCats" datasource="#variables.dsn#"
> username="#variables.dbusername#" password="#variables.dbpassword#">
>                       SELECT *
>                       FROM categories
>                       WHERE 1=1
>                       <cfif isDefined("arguments.cat_id")>
>                               AND cat_id = <cfqueryparam
> cfsqltype="cf_sql_integer" value="#arguments.cat_id#">
>                       </cfif>
>                       <cfif isDefined("arguments.parent_id")>
>                               AND parent_id = <cfqueryparam
> cfsqltype="cf_sql_integer" value="#arguments.parent_id#">
>                       </cfif>
>               </cfquery>
>               
>               <cfreturn getCats />
>       </cffunction>
>
> <cffunction name="display_categories" output="true" access="public">
>               <cfargument name="parent_id" type="numeric" required="yes">
>               <cfargument name="level" type="numeric" default="0">
>               
>               <cfif arguments.level EQ 0>
>             <cfset variables.output = "">
>         </cfif>
>       
>               <cfset getCategories =
> get_categories(parent_id=arguments.parent_id)>
>               
>                       <cfloop query="getCategories">
>                               <cfset variables.output = variables.output &
> "
>                               <table width='640' border='0'
> cellspacing='0' cellpadding='5'>
>                               <tr>
>                               <td>#getCategories.cat_title#</td>
>                               <td width='50'><div align='center'><a
> href='index.cfm?action=product_manager&page=editCat&cat_id=#getCategories.ca
> t_id#'>Edit</a></div>
>                               </td>
>                               <td width='50'><div align='center'><a
> href='index.cfm?action=product_manager&page=categories&step=delete&cat_id=#g
> etCategories.cat_id#' onClick='GP_popupConfirmMsg('Are you sure you wish to
> delete the category #getCategories.cat_title#? This action cannot be
> undone.');return document.MM_returnValue'>Delete</a></div>
>                               </td>
>                               </tr>
>                               </table>
>                               #arguments.level# ID:#getCategories.cat_id#
>                               ">
>                               <cfif isNumeric(getCategories.cat_id)>
>                                       <cfset variables.output =
> variables.output &
> display_categories(parent_id=getCategories.cat_id,level=arguments.level +
> 1)>
>                               </cfif>
>                       </cfloop>
>               
>               <cfreturn variables.output />
>       </cffunction>
>
> The recordset is not returning the heirarchy correctly however. Can anyone
> see what (big) mistakes I am making??
>
> Thanks heaps.
> mike
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289063
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to