Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) 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 January 2nd, 2006, 09:10 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default two while loops inside each other

hello all
can we write to while loops with different recordsets????something like this:(rs,rs1 are different recordsets)
rs.movefirst()
rs1.movefirst()
while not rs.eof
while not rs1.eof
*****some statements******
rs.moevenext()
rs1.movenext()
wend
wend
it gives me runtime error


 
Old January 2nd, 2006, 04:36 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What is it you're trying to accomplish? This loop will indeed cause problems, because inside the inner loop, you use MoveNext on the outer recordset as well.

Can you explain your requirements for these loops?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 3rd, 2006, 01:14 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default

I have a sample of unit in the first recordset(all unist are the same).and the Date of start of each unit and the unit name in the second recordset.I want to have the date of start of each item in the unit sample.for example the dateof start for item1 of unit1,item2 of unit1 and itemi of unitj.
its like a 2*2 matrix:[i,j]=[itemi,dateofstarti]


 
Old January 3rd, 2006, 03:44 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default

I replace the outer rs.movenxt() after the inner loop wend.it shows the page but i think it dos'nt loop over two recordsets.becouse it doesn't show me anything.whould you please help me





 
Old January 3rd, 2006, 04:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It could be me, but once again I have trouble understanding your business logic. That has happened in the past as well, and I then recommended writing it out on a piece of paper, describing each individual step.

From this, you can write some pseudo code that describes what you want the code to do. E.g. something like this:
Code:
1. Get Units
2. For Each Unit
 2a Get dates based on Unit
 2b Get Measurements based on Unit
 2c For each Date and Measurement
   2c1 Write out Unit, Date and Measurement
 loop
loop
I am just making something up here, but I am sure you get the idea.

With this pseudo code, it's much easier to understand how you should structure your code. This is much mor effective than randomly moving MoveNext statements around, hoping your code suddenly starts working...

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 4th, 2006, 06:19 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default

that's the pseudo code:
1.get units from table1
2.for each unit
       1.get unit desciptions(they are in table2)
       2.create desciption of each unit
       3.do some calculations with description of each unit
       4.return the calculations for each unit


 
Old January 4th, 2006, 06:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, it shouldn't be too hard to come up with the rest of the code (although for your own sake, adding more detail to your own pseudo code would really help):
Code:
SQL = "SELECT * FROM Units"
rs1.Open SQL
While Not rs1.EOF
  SQL2 = "SELECT * FROM Measurements WHERE UnitID = " & rs1("Id")
  rs2.Open SQL2
  While Not rs2.EOF
    Response.Write(rs2("SomeField"))
    rs2.MoveNext()
  Loop
  rs1.MoveNext()
Loop
This code loops through all the units. FOr each unit, it accesses the database again and gets additional information that is also looped through.

Please note that this may not be the most efficient way to do it; maybe you can do it with a single recordset and 1 loop.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
break for-each loops, or limit amount of loops warhero XSLT 2 July 4th, 2007 02:18 AM
Two Loops iloveoatmeal Classic ASP Basics 5 September 26th, 2005 09:59 AM
While loops and For loops in XSLT spencer.clark XSLT 1 August 5th, 2005 09:50 AM
loops Hudson40 Access VBA 1 February 4th, 2005 12:58 PM
loops flyn Javascript How-To 1 November 21st, 2003 04:59 AM





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