Have you considered an alternate storage method for your users/subusers? Or possibly put some restraints in place? 22 levels deep sounds a little excessive.
I've had good luck storing related records using a parent-child relationship (or adjacency list) method: http://www.codeproject.com/aspnet/HierDataGrid.asp (scroll down to the "Parent-child relationship DB table" header). Having this sort of relationship allows you to do most of the work on the SQL end. Here's an alternate method called the Nested Set model: http://www.developersdex.com/gurus/articles/112.asp -----Original Message----- From: Jessica Kennedy [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 23, 2007 1:11 PM To: CF-Talk Subject: Help cleaning up my code... hi, I posted a while ago about an outofmemoryerror: java heap space problem. Anyway, it's looking like the only way to fix this problem is to re-write some programming. The program I wrote is for displaying a "tree structure" of people in a database based on the upline person. IE: i recruit someone, who recruits 2 people, who recruit 3 pl, & so on down to 22 levels with a max of 2 ppl that can be under you. The code that I have works, but it takes of a crazy amount of memory, which is bad. the working version is viewable at http://dummbo.triadwebcrafters.com/dealers/dealer_tree.cfm . I know its a lot of coding, but if somebody can think of a way to make this thing more manaeable, I would really appreciate it! Here is the coding I have for the page: <cfparam name="SESSION.dealerid" default="9999999"> <cfparam name="FORM.dealerID" default="#SESSION.dealerID#"> <cfparam name="form.stoplooping" default="0"> <cfquery name="rsgetname" datasource="cfdummbo"> SELECT dealerID, first_name, last_name FROM tbldealers WHERE dealerID = #FORM.dealerID# </cfquery> <cfset display=0> <cfset namesave=ArrayNew(1)> <cfset downlinecount=0> <cfset newname=ArrayNew(1)> <cfset newname[99999999]=#FORM.dealerID#> <cfset totalcount=0> <cfset oldestdownlinecount=0> <cfset looptimes=0> <cfset displaynamecount=0> <cfset oldtotalcount=-1> <cfset oldlevelis=1> <cfset division=50> <cfset flag="no"> <cfset accumulation=0> <cfset blankcount=0> <cfset oldaccumulation=0> <cfset oldlevelnumberlow=0> <cfset peoplecount=0> <cfset totalpeoplecount=0> <cfset displaypeoplecount=ArrayNew(1)> <cfset qual_count=0> <cfset stoplooping=#form.stoplooping#> <cfset pagetitle="My Downline"> <cfinclude template="hidden_header.cfm"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><cfoutput>#title#</cfoutput></title> <link href="dealers_style.css" rel="stylesheet" type="text/css" media="tv,screen,tty" /> <style type="text/css"> table {text-align:center;} </style> </head> <body> <div align="center"><img src="images/dealers_main_banner.jpg" alt="Dummbo.com Hot Names...Cool Cash" /> </div> <h2>View All Members In Your Donwline</h2> <!--Sets the opening table and creates first part of the "1st level" table--> <table border="1" cellpadding="5" cellspacing="0" width="100%" align="center"> <tr> <td><strong> <cfif #session.dealerID# eq #form.dealerID#> Me, <cfoutput>#rsgetname.first_name# #rsgetname.last_name# (ID: #session.dealerid#)</cfoutput> <cfelse> <a href="dealer_details.cfm?dealerID=<cfoutput>#FORM.dealerID#</cfoutput>"><cfo utput>#rsgetname.first_name# #rsgetname.last_name#</cfoutput></a> </cfif> </strong></td> </tr> </table> <table border="1" cellpadding="5" cellspacing="0" width="100%" align="center"> <tr> <!--Main loop. everything else is inside of this loop.--> <cfloop condition="(flag EQ 'no')"> <cfset stoplooping=#stoplooping# + 1> <!--Sets the next name to run. Default is 9999999, which will display the SESSION.dealerID parameter.--> <cfif #downlinecount# EQ 0> <cfset display=99999999> <cfelse> <cfset display=#looptimes#> </cfif> <!--Runs the next name in the list.--> <cfquery name="rsmatrix" datasource="cfdummbo"> SELECT dealerID, first_name, last_name, upline FROM tblDealers WHERE upline = #newname[display]# </cfquery> <!--Sets the name and dealerID temporarily, will set permanently in next section.--> <cfset cyclecount=0><!--IMPORTANT! Must reset each loop!--> <cfoutput query="rsmatrix"> <cfset downlinecount= downlinecount +1> <cfset cyclecount= cyclecount +1> <cfset 'namesave#cyclecount#'='#first_name# #last_name#'> <cfset 'dealerID#cyclecount#'='#dealerID#'> </cfoutput> <!-- This section sets "blank" or "(two dashes'-')" value for extra people not in downline & assigns unique ID's to each person --> <cfif newname[display] eq 999999> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]='--'> <cfset newname[TOTALCOUNT]=999999> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]='--'> <cfset newname[TOTALCOUNT]=999999> <cfelse> <cfif cyclecount eq 0> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]='Blank'> <cfset newname[TOTALCOUNT]=999999> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]='Blank'> <cfset newname[TOTALCOUNT]=999999> </cfif> <cfif cyclecount eq 1> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]="#NAMESAVE1#"> <cfset newname[TOTALCOUNT]="#dealerID1#"> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]="Blank"> <cfset newname[TOTALCOUNT]=999999> </cfif> <cfif cyclecount eq 2> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]="#NAMESAVE1#"> <cfset newname[TOTALCOUNT]="#dealerID1#"> <cfset totalcount=totalcount+1> <cfset namesave[TOTALCOUNT]="#NAMESAVE2#"> <cfset newname[TOTALCOUNT]="#dealerID2#"> </cfif> </cfif> <!-- This section sets level number & values associated with it --> <cfset calculatelevel=1> <cfset levelis=0> <cfset accumulation=0> <cfset levelnumberlow=0> <cfset levelnumber= ArrayNew(1)> <cfloop condition="totalcount GREATER THAN accumulation"> <cfset calculatelevel=calculatelevel*2> <cfset accumulation=calculatelevel+accumulation> <cfset levelis=levelis+1> <cfset levelnumber[levelis]=calculatelevel> <cfset levelnumberlow=calculatelevel-1> </cfloop> <!--<cfoutput>Level #levelis#=#calculatelevel# ; That's #levelnumberlow# - #accumulation# People.<br /></cfoutput>--> <cfif #levelis# GT #oldlevelis#><!--Performs certain actions if this loop is "leveling up"--> <cfloop index="loopcount" from="#oldlevelnumberlow#" to="#oldaccumulation#"> <cfif #newname[loopcount]# eq 999999><!--Counts number of blank entries--> <cfset blankcount=blankcount+1> <cfelse> <cfset peoplecount=peoplecount+1> <cfset totalpeoplecount=totalpeoplecount+1> </cfif> </cfloop> <cfif #oldcalculatelevel# eq #blankcount#><!--Stops program from running if entire level is blank--> <cfset flag="yes"> <cfset displaypeoplecount[oldlevelis]=#peoplecount#> <cfelse> <cfset displaypeoplecount[oldlevelis]=#peoplecount#><!--sets # of ppl per level--> <cfset peoplecount=0> <cfset blankcount= 0> </cfif> <cfif #oldlevelis# GTE 3><!--Shows only certain # of levels per page--> <cfset flag="yes"> </cfif> <cfif #stoplooping# GTE 22><!--Stops levels shown at 22--> <cfset flag="yes"> </cfif> <cfset division=100/#accumulation#> <!--Sets percent of table for each cell--> </tr> </table> <cfif flag eq 'no'><!--Starts new table for next level down--> <table border="1" cellpadding="5" cellspacing="0" width="100%" align="center"> <tr> </cfif> </cfif> <!-- Prints out results for each level by two's--> <cfif flag eq 'no'> <cfloop condition="totalcount GREATER THAN displaynamecount"> <cfset displaynamecount=displaynamecount+1> <td width="<cfoutput>#division#</cfoutput>%"> <cfif #namesave[displaynamecount]# eq "Blank" OR #namesave[displaynamecount]# eq "--"> <cfoutput>#namesave[displaynamecount]#</cfoutput> <cfelse> <form name="viewdl" action="dealer_tree.cfm" method="post"> <a href="<cfoutput>dealer_details.cfm?dealerID=#newname[displaynamecount]#</cfo utput>"><cfoutput>#namesave[displaynamecount]#</cfoutput></a><br /> <input type="hidden" name="dealerID" value="<cfoutput>#newname[displaynamecount]#</cfoutput>" /> <input type="hidden" name="stoplooping" value="<cfoutput>#stoplooping#</cfoutput>" /> <input name="submit" type="submit" value="Downline..." /> </form> </cfif> </cfloop> <!--Sets current variables to hold for use on next loop through--> <cfset oldlevelis=#levelis#> <cfset oldaccumulation=#accumulation#> <cfset oldlevelnumberlow=#levelnumberlow#> <cfset oldcalculatelevel=#calculatelevel#> <cfset looptimes=looptimes+1><!-- set loop for # of times to run through cycle --> </cfif> </cfloop> <!--End of outermost loop--> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| ColdFusion is delivering applications solutions at at top companies around the world in government. Find out how and where now http://www.adobe.com/cfusion/showcase/index.cfm?event=finder&productID=1522&loc=en_us Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:291865 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

