Forums
This topic is locked
loop based on two id fields and list results
27 May 2003 19:35:23 Pat Kelly posted:
What I'm trying to do is connect to my database, select "parent" based on the request.querystring("id'), then do a loop until "parent" = 0, sorting the list from the parent=0 to the request.querystring("id').
Example: Databse is similar to below
______________
| id | parent | pagename
----------------------
| 01 | 03 | jo
| 02 | 05 | sam
| 03 | 00 | sandi
| 04 | 02 | marry
| 05 | 01 | greg
| 06 | 00 | john
| 07 | 06 | ralph
The results I'm looking for on the id=04 (marry) request would be: sandi, jo, greg, sam, marry.
What I currently have doesn't work:
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset"
rs.ActiveConnection = MM_dbcon_STRING
rs.Source = "Select pagename from pages where id <= " & Request.querystring("id" & " ORDER BY parent"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open()
str = ""
while not rs.eof
str = str & rs("pagename" & ", "
rs.movenext
wend
response.write(mid(str,1,len(str)-2))
rs.Close()
Set rs = Nothing