...

View Full Version : Help with nested while loop - classic ASP



Fictitus
05-15-2007, 07:20 AM
Hi,
I have list of asp pages that are grouped together by sections they belong to - So section Add could have pages add.asp and add2.asp, section Delete could have pages del.asp and del2.asp so that the final display should look like this

Click on link below:
Add
Add Item <- hyperlink to add.asp
Add Item2 <- hyperlink to add2.asp

Delete
Delete Item <- hyperlink to del.asp
Delete Item2 <- hyperlink to del2.asp

The recordset returned by the query contains the following fields:
Sections - The name of the section the page belongs to (Add, Delete)
PagePath - The path to the page (http://localhost/test/add.asp)
PageDescription - Description of page (Add Item, Delete Item)

In the code below I get the following error when it comes out of the inner loop and goes back to the outer loop.
Error Type: (0x80020009) Exception occurred.

Any help to resolve this would be much appreciated. Thanks!

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open strQuery, strConnect, adOpenStatic, adLockOptimistic, adCmdText

If Not objRS.EOF Then
Response.Write "<br>Click on link below:<br><br>"
objRS.MoveFirst

While NOT objRS.EOF
strSections = objRS("Sections")
Response.Write objRS("Sections") & "<br>"

While strSections = objRS("Sections")
Response.Write "<a href=" & chr(34) & objRS("PagePath") & chr(34) & ">" & ObjRS("PageDescription") & "</a><br>"
objRS.MoveNext
Wend

Wend

objRS.Close
Set objRS = Nothing
End If

Fictitus
05-15-2007, 08:40 AM
I figured it out...here is the working code snippet

If Not objRS.EOF Then
Response.Write "<br>Click on link below:<br><br>"
objRS.MoveFirst

strSections = objRS("Sections")
Response.Write "<b><u>" & strSections & "</u></b><br>"
While NOT objRS.EOF
If strSections = objRS("Sections") Then
Response.Write "<li><a href=" & chr(34) & objRS("PagePath") & chr(34) & ">" & ObjRS("PageDescription") & "</a></li><br>"
objRS.MoveNext
Else
If NOT objRS.EOF Then
strSections = objRS("Sections")
Response.Write "<b><u>" & strSections & "</u></b><br>"
End If
End If
Wend

objRS.Close
Set objRS = Nothing
End If



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum