Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2004, 02:06 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pbhupal Send a message via Yahoo to pbhupal
Default Help needed to create nested do while

Hello,

I am trying to print a record set information that looks like:
TheaterID, MoviedID, MovieTitle (ordered in similar fashion)
1, 50, a
1, 51, b
1, 52, c
2, 53, d
2, 50, a
3, 54, e
3, 55, f

The outer loop is driven by the condition while not rs.eof. I am performing a similar while loop inside the outer loop to loop through all the MovieTitle contolled by TheaterID. I run into problem when TheaterID changes there by a record in the process of rs.movenext. How can I write the inner loop so that I can print all the MovieTitle for each of the TheaterID? Below is the snippet of code that I have created.


rs.Open mySQL, cn, adOpenDynamic
Dim n


Do while Not rs.eof
n = rs.Fields("TheaterID").value
%>
        <tr>
          <td width="100%" bgcolor="#CDD9AB">
            <p align="center" class="Sface"><b><%=rs.Fields("TheaterName").value %></b><br>
          </td>
        </tr>
        <%
Do while rs.Fields("TheaterID").value = n
%>
              <tr bgcolor="#EFF3E4">
                <td valign="top" width="39%" class="Sface"><A class="face" href="/Movies/View.asp?MovieID=<%=rs.Fields("MovieID").value %>"><%=rs.Fields("MovieTitle").value %></A></td>
              </tr>
<%
Rs.movenext
Loop
%>
            </table>
          </td>
        </tr>
<%
Rs.movenext
Loop
%>

How best can this scenario be coded? All help is appreciated. Thanks.

Paul

 
Old June 30th, 2004, 03:22 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

you repeat the Rs.MoveNext before the end of the second loop

Ahmed Ali
Software Developer
 
Old July 1st, 2004, 12:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I would say that, you will reach EOF within your inner LOOP And that would return ERROR everytime you run this, as you don't check for EOF there.

The best way I would say is to use one LOOP. And use IF contruct inside to check for same TheatreID and display the data accordingly.

Code:
PrevTheatreId = 0
Do while Not rs.eof
    If rs("TheaterID") <> PrevTheatreId Then ' use CINT() if required.
        PrevTheatreId = rs("TheaterID")
%>
        <tr>
          <td width="100%" bgcolor="#CDD9AB">
            <p align="center" class="Sface"><b><%=rs.Fields("TheaterName").value %></b><br>
          </td>
        </tr>
        <%
End IF
%>
              <tr bgcolor="#EFF3E4">
                <td valign="top" width="39%" class="Sface"><A class="face" href="/Movies/View.asp?MovieID=<%=rs.Fields("MovieID").value %>"><%=rs.Fields("MovieTitle").value %></A></td>                
              </tr>
<%
Rs.movenext
Loop
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Repeaters to create hierarchy Lord__Chaos ASP.NET 2.0 Basics 0 May 26th, 2006 12:37 PM
Nested Query Help Needed Corey Access 2 April 26th, 2006 02:17 PM
Create Variable when needed (dynamic) mkhan SQL Server 2000 1 February 22nd, 2006 11:01 PM
Nested IIF Statement Help Needed Corey Access 4 November 17th, 2005 10:19 AM
Help needed in constructing create table statement method Access VBA 0 April 28th, 2005 11:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.