Recursion Headaches

Public Sub getChildren(parent, level)
 
  set rs1 = server.CreateObject("ADODB.RecordSet")
  rs1.cursorlocation = 3
  rs1.Open "select a.* from _pages a left join _pagemenu b on a.page_name = b.child_page where b.base_page = '" & rs("page_name") & "' order by page_name asc", dsn, 2, 3
  
  for j = 0 to rs1.RecordCount - 1
   response.write space(v + 1) & rs1("page_name") & "
"
   getChildren rs1("page_name"), level
   rs1.movenext
  next
  
  rs1.close
  
 end Sub

My brain must be off today.  I can't figure out why this isn't working for me...

It's basically a home-grown CMS, with nested menus.  I'm trying to use recursion to get a tree of the menu structure, but it's biffing on me. 

What am I doing wrong?

EDIT:  Figured it out .  It was in the SQL statement.  rs("page_name") should have been “level”

Print | posted on Wednesday, March 29, 2006 9:20 AM

Feedback

# re: Recursion Headaches

left by Jason Coyne at 3/30/2006 9:19 AM Gravatar
If you are doing this in oracle, the "connect by" keyword will give this to you in one query, with a lot better performance and memory usage.

In SQL server (They might have this in 2005, but I am sure its not in earlier versions) they do not support this syntax, but there are several solutions that can emulate "connect by" in sql server if you just google for it.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 1 and 2 and type the answer here: