Parent/Child Algorithm Problem

1. Junior Member
Join Date
Dec 1969
Posts
13

## Parent/Child Algorithm Problem

Hi, below is an algorithm, from 4guysfromrolla.com, for retrieving and displaying categories in a parent/child relationship. Now everytime I try to run this script, I get an "Out of Stack Space" error. Any ideas?? You can see a live demo of the problem at http://www28.brinkster.com/phatrade/cat.asp The URL where I got the script is http://www.4guysfromrolla.com/webtech/101202-1.shtml Any help would be greatly appreciated.<BR><BR>Thanks in advance,<BR><BR>-Scott S.<BR><BR><BR><BR>&#060;%<BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>sConnec tion = "Provider=Microsoft.Jet.OLEDB.4.0;" & _<BR> "Data Source=" & Server.MapPath("USERNAMEdbdb.mdb") & ";" & _<BR> "Persist Security Info=False"<BR>Conn.Open(sConnection)<BR><BR>sql = "select * from categories"<BR>Set RS = Conn.Execute(sql)<BR><BR>Dim aMyCategories()<BR>numRows = 0<BR>Do While NOT RS.EOF<BR> numRows = numRows + 1<BR> ReDim Preserve aMyCategories(3, numRows)<BR> aMyCategories(0, numRows - 1) = RS(0)<BR> aMyCategories(1, numRows - 1) = RS(1)<BR> aMyCategories(2, numRows - 1) = RS(2)<BR> aMyCategories(3, numRows - 1) = RS(3)<BR> RS.MoveNext<BR>Loop<BR><BR><BR><BR>&#039;First, populate a Recordset with the SQL statement:<BR>&#039; SELECT CategoryID, Name, Link, ParentID FROM Category<BR>&#039;Then, dump the contents of the Recordset into an array <BR>&#039; (named, say, aMyCategories)<BR><BR>&#039;To display the categories, do:<BR>Dim str<BR>str = DisplayCategories(aMyCategories, 0, 0)<BR>Response.Write(str)<BR><BR>&#039;---------------------------------------------------------------------<BR><BR>Function DisplayCategories(aCategories, ByVal iCurID, ByVal iDepth)<BR> Dim strHTML<BR> strHTML = ""<BR> <BR> Const CategoryID = 0, Name = 1, Link = 2, ParentID = 3<BR> <BR> Dim iNumRecords, iLoop, i<BR> iNumRecords = UBound(aCategories, 2)<BR> For iLoop = 0 to iNumRecords<BR> If CInt(aCategories(ParentID, iLoop)) = CInt(iCurID) then<BR> For i = 1 to iDepth<BR> strHTML = strHTML & "&nbsp;"<BR> Next<BR> strHTML = strHTML & "&#060;a href=""" & aCategories(Link, iLoop) & """&#062;" & _<BR> aCategories(Name, iLoop) & "&#060;/a&#062;&#060;br /&#062;"<BR><BR> strHTML = strHTML & _<BR> DisplayCategories(aCategories, aCategories(CategoryID,iLoop), iDepth+1)<BR> End If<BR> Next<BR><BR> DisplayCategories = strHTML <BR>End Function<BR><BR>mySQL.close<BR>set mySQL = nothing<BR>%&#062;<BR>

2. Senior Member
Join Date
Dec 1969
Posts
449

## RE: Parent/Child Algorithm Problem

Sounds like some part of your code is looping indefinitely till you eventaully run out of stack space.<BR>You should debug your params in your loops.<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
13

## RE: Parent/Child Algorithm Problem

James,<BR><BR>Thanks for responding to my post. Any idea on how to do this?? Sorry I am new to ASP :(<BR><BR>-Scott.

4. Senior Member
Join Date
Dec 1969
Posts
449

## RE: Parent/Child Algorithm Problem

Scott<BR><BR>On a quick look the problem appears to be the line<BR>strHTML = strHTML & _ <BR> DisplayCategories(aCategories, aCategories(CategoryID,iLoop), iDepth+1) <BR><BR>Your recalling the same function from within the function???

5. Senior Member
Join Date
Dec 1969
Posts
449

## OK I see...

I read the article you refered to, your problem is with your array. Create the array as the article tells you...<BR><BR>aMyCategories = RS.GetRows()<BR><BR>Also at the end you are closing an object you didn&#039;t open.<BR>Close the connection and record set you opened.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•