Seem you are working on multi-level marketing chart!! :cheesy:
You can use looping function to call database repeatedly:
' user A login
userid = Request("userid")
' query database for user A
counter = 1
select username from ... where user_id = "&userid&"' "
...
While Not RS.EOF
downline = RS("username")
response.write "staff: " & downline
counter = counter +1
RS.MoveNext
WEND
For x = 1 to counter
' repeat the database query here
' ...
Next
'if you are going down further, repeat the looping
Alternatively you may use array function to store "downline" name and query the database using
user_id = "&staff[0]&"' OR user_id = "&staff[1]&"' OR ...