Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 HELP HELP -- Multiple Loops With One Recordset
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Lycaster
New Member

USA
60 Posts

Posted - 21 August 2001 :  10:34:42  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
I am trying to enumerate multiple table loops in the same asp file with only one recordset.

Only one loop will display at a time. The code I am using is as follows.

 
' Generate Categories
Do Until oProducts.EOF
If sCurCount <> oProducts("Category") Then
sCurCount = oProducts("Category")
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & """>" & oProducts("Category") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sCategory = sCategory & strTemp
End If
oProducts.MoveNext
Loop


I need to have 4 or 5 loops from different fields in the recordset. Can I even use multiple "DO's"?

Thanks for any help.

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 21 August 2001 :  10:49:48  Show Profile  Visit Kat's Homepage
You can loop through a recordset as many times as you like by putting a rs.moveFirst at the start of a Do Loop. However, this really isn't very effcient.

You could also load your recordset into an array using the GetRows() method and then loop around this array instead of wasting resources keeping a recordset open.

What exactly are you trying to achieve?

KatsKorner
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 21 August 2001 :  11:34:33  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
Kat,

I am creating a "search-like" page right now, for my products. I want the user to be able to select the following:

Designer
- DKNY
- Gucci ect..

Category
- Suits
- Pants ect...

Type
- Casual
- Business ect..

Each one of these needs to be a loop. Looping through my rs. I want these 3 loops to display on the same page. Currently, using the code I posted above. I am able to enumerate my categories just the way I want them. I use the "sCurCount" as my counter to make sure the loop only displays one occurrence at a time.

So now that I have 1 loop working I just need the other 2.

I hope I was clear. Sometimes it’s hard explaining what I am looking for. Tell me what you think, and thanks allot for your help.

Jared

Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 21 August 2001 :  11:42:01  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
I am going on the assumption you want to do something like this:
Display each unique category. Within each category, display all the types of products. Within each type, display all the product names. Within each product name, display all the colors of the product.

I would code it like this:
 
' Generate Categories
Do Until oProducts.EOF
HigherChange = False
If sCurCat <> oProducts("Category") Then
sCurCat = oProducts("Category")
HigherChange = True
sCurType = "" ' Wipe it out to print the first type
sCurName = "" ' Wipe it out to print the first name
sCurColor = "" ' Wipe it out to print the first color
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & """>" & oProducts("Category") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sCategory = sCategory & strTemp
ElseIf sCurType <> oProducts("Type") then
sCurType = oProducts("Type")
sCurName = "" ' Wipe it out to print the first name
sCurColor = "" ' Wipe it out to print the first color
HigherChange = True
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & "&Type=" & oProducts("Type") & """>" & oProducts("Type") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sType = sType & strTemp
ElseIf sCurName <> oProducts("Name") then
sCurName = oProducts("Name")
sCurColor = "" ' Wipe it out to print the first color
HigherChange = True
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & "&Type=" & oProducts("Type") & "&Name=" & oProducts("Name") & """>" & oProducts("Type") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sName = sName & strTemp
ElseIf sCurColor <> oProducts("Color") then
sCurColor = oProducts("Color")
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & "&Type=" & oProducts("Type") & "&Name=" & oProducts("Name") & "&Color=" & oProducts("Color") & """>" & oProducts("Color") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sColor = sColor & strTemp
End If
If HigherChange = False then ' This code added to allow it to loop back through for other changes....
oProducts.MoveNext
end if
Loop


If this doesn't do what you need, then please let us know what you actually need and we'll try to fix you up....

Dave Maxwell
--------------
Proud to be a "World Class" Knucklehead
Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 21 August 2001 :  11:44:42  Show Profile  Visit Kat's Homepage

 
' Generate Categories
Do Until oProducts.EOF
If sCurCount <> oProducts("Category") Then
sCurCount = oProducts("Category")
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & """>" & oProducts("Category") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sCategory = sCategory & strTemp
End If
oProducts.MoveNext
Loop
oProducts.MoveFirst
'Loop through next list - Designers
Do Until oProducts.EOF
....
Loop
oProducts.MoveFirst
'Loop through next list - Whatever comes next
Do Until oProducts.EOF
....
Loop



That would do it but as I said before, it isn't all that efficient. I could probably devise a better way but I can't see your database table/s or SQL.

I have done exactly what you are doing on a site that is soon going live (for the Style Industry), except each type of ist is a lookup table on the database and therefore easier to access than yours seems to be.


KatsKorner
Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 21 August 2001 :  12:31:37  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
Dave,

Thanks for that code, I am very impressed. I am still learning ASP and about to dive into the .NET world...yipe...People like you and Kat make my life allot easier.

I am going to try the code out now, I will update you guys on my progress. Thanks again!

- Jared
http://www.oxcyon.com

Go to Top of Page

Lycaster
New Member

USA
60 Posts

Posted - 21 August 2001 :  13:46:54  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
Dave,

I got everything working but the last "ElseIf" in the code snippit. I changed sCurColor to sCurPP to pull from a category list called "Price Point"

For some reason the counter doent seem to be working. This is what I get when I run the page:

Price Point:

High
High
Medium
Low
High
High
High

When I need it to be:

Price Point:

High
Medium
Low

Everything else works though. I just don't understand why this last one is giving me problems.

Code Snipit:

' Generate Categories
Do Until oProducts.EOF
HigherChange = False
If sCurCat <> oProducts("Category") Then
sCurCat = oProducts("Category")
HigherChange = True
sCurType = ""
sCurDesigner = ""
sCurPP = ""
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Category=" & oProducts("Category") & """>" & oProducts("Category") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sCategory = sCategory & strTemp
ElseIf sCurType <> oProducts("Type") Then
sCurType = oProducts("Type")
sCurDesigner = ""
sCurPP = ""
HigherChange = True
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Type=" & oProducts("Type") & """>" & oProducts("Type") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sType = sType & strTemp
ElseIf sCurDesigner <> oProducts("Designer") Then
sCurDesigner = oProducts("Designer")
sCurPP = ""
HigherChange = True
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?Designer=" & oProducts("Designer") & """>" & oProducts("Designer") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sDesigner = sDesigner & strTemp
ElseIf sCurPP <> oProducts("Price Point") Then
sCurPP = oProducts("Price Point")
strTemp = "<FONT face=""Geneva, Arial, Helvetica, san-serif"" size=""2"">"
strTemp = strTemp & "<A href=""ShowProd.asp?PricePoint=" & oProducts("Price Point") & """>" & oProducts("Price Point") & "</A>"
strTemp = strTemp & "</FONT><BR>"
sPPoint = sPPoint & strTemp
End If
If HigherChange = False Then ' This code added to allow it to loop back through for other changes
oProducts.MoveNext
End If
Loop


Thanks again.

Jared

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07