travisbrown
Technical User
- Dec 31, 2001
- 1,016
I'm trying to nest some lists using a recursive function. My usual method of getting data from a db is using GetRows() and looping through using FOR/NEXT.
Using this method with recursive function, I think I'd be overwriting the iteration variable values (x) as soon as I hit the second loop, so I'm wondering what the best alternative would be.
There's a top level table, then one that holds all the sub-record relationships for records with sub-records.
I cannot change the table design, so I'm stuck with working with it as is.
Using this method with recursive function, I think I'd be overwriting the iteration variable values (x) as soon as I hit the second loop, so I'm wondering what the best alternative would be.
There's a top level table, then one that holds all the sub-record relationships for records with sub-records.
I cannot change the table design, so I'm stuck with working with it as is.
Code:
sSQL = "SELECT pa_subj.subj_id,pa_subj_relation.* FROM pa_subj LEFT OUTER JOIN pa_subj_relation ON pa_subj.subj_id = pa_subj_relation.subj_id_child WHERE SUBJ_ID_PARENT IS NULL"
arrSubjects = GetRows(sSQL)
response.write "<ul>"
FOR i = 0 TO UBOUND(arrSubjects,2)
response.write "<li>"
response.write arrSubjects(0,i)
CALL FindSubCategory(arrSubjects(0,i))
response.write "</li>"
NEXT
response.write "</ul>"
FUNCTION FindSubCategory(id)
sSQL = "SELECT SUBJ_ID, SUBJ_ID_SUB FROM PA_SUBJ_SUBSUBJ WHERE SUBJ_ID = '" & id & "'"
arrSubSubj = GetRows(sSQL)
IF isArray(arrSubSubj) THEN
FOR x = 0 TO UBOUND(arrSubSubj,2)
response.write "<ul>"
response.write "<li>"
response.write arrSubSubj(1,x)
CALL FindSubCategory(arrSubSubj(1,x))
response.write "</li>"
response.write "</ul>"
NEXT
END IF
END FUNCTION
FUNCTION GetRows(input)
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = dbconn
rs.Source = input
rs.Open()
IF NOT rs.EOF AND NOT rs.BOF THEN
GetRows = rs.GetRows()
END IF
rs.Close()
Set rs = Nothing
END FUNCTION