Recursive ASP call to Access database

Results 1 to 2 of 2

Thread: Recursive ASP call to Access database

  1. #1
    Join Date
    Dec 1969

    Default Recursive ASP call to Access database

    Hi, I have a table in an Access db that has these fields:<BR><BR>UserID UserName UserParent<BR><BR>Every User has a UserParent who is the person that added them to them to the database. <BR>Every User has the ability to add other Users. <BR>Not every User will add other "sub-users"<BR><BR>I want to create a tree showing the relationship of all the users in the table.<BR>Bob<BR>---Dan<BR>---George<BR> ---Lisa<BR> ---Max<BR> ---Tom<BR> ---Louis<BR>---Bill<BR> ---Fred<BR>---Max<BR>---Joan<BR> ---Willard<BR> ---Ben<BR> ---Marvin<BR>---Betty<BR><BR>and so on. Basically, I want to create a tree structure. I imagine the best way to do this is to call the database recursively but am not sure how to go about this. All I want to do is print the tree structure in html to a webpage. <BR><BR>Any thoughts?<BR>Thanks,<BR>Steve<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Never never never do that!

    Horrible thing to do!<BR><BR>Much much better to load all the info into memory using ONE recordset and GetRows and then use recursion in VBScript (or even recursion in the browser, in JavaScript!) to make the tree.<BR><BR>In VBS:<BR><BR>&#060;%<BR>SQL = "SELECT UserID, UserName, UserParent FROM table ORDER BY UserID"<BR>Set RS = yourConnection.Execute( SQL )<BR>data = RS.GetRows<BR><BR>maxrow = UBound( data, 2 )<BR>CONST COL_ID = 0<BR>CONST COL_NAME = 1<BR>CONST COL_PARENT = 2<BR><BR>Sub GetChildren( ByVal ofParent, ByVal indent )<BR> Dim row &#039; important!<BR> For row = 0 To maxrow<BR> If data( COL_PARENT, row ) = ofParent Then<BR> Response.Write indent & data(COL_NAME, row) & "&#060;br/&#062;"<BR> GetChildren data(COL_ID, indent & "-- ")<BR> End If<BR> Next<BR>End Sub<BR><BR>&#039; and get it all started:<BR>GetChildren 0, ""<BR><BR>%&#062;<BR><BR>This assumes (1) the column UserParent contains the ID number of the person&#039;s parent (not the parent&#039;s name) and (2) persons with no parent have a UserParent of zero assigned.<BR><BR><BR>

Posting Permissions

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