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)
 Horizontal Recordset Looping in ASP
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Lycaster
New Member

USA
60 Posts

Posted - 20 August 2001 :  13:19:29  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
I just posted a rather complicated question about a horizontal loop. Instead of approaching my problem in that manner, I was hoping someone in here could explain how to do this.

I am trying to find the easiest way to loop through a recordset horizontally. Instead of the cursor looping 1 record at a time that usually just racks up one after the other, I want my recordsets to populate 3 columns wide in a table, so the loop in theory would display 3 records next to each other. After 3 records have been displayed, the loop would rack 3 more columns in a new row underneath it.

Example:

Record 1 Record 2 Record 3

Record 4 Record 5 Record 6

Can anyone explain to me how to do this? Or maybe some code you have laying around that might help.

Thanks for any help.

Jared


Cyber Paladin
New Member

55 Posts

Posted - 20 August 2001 :  16:01:37  Show Profile  Visit Cyber Paladin's Homepage
Easiest way I can see is keep a running counter in the loop and right in a new line change everytime the counter is evenly divisable by 3. (or write a new line in a table)

So:

do while not rst.eof
if (counter / 3) = int(counter / 3) then response.write "<br>"
response.write rst("name")
counter = count + 1
rst.movenext
loop

Remember... Amateurs built the Ark, but professionals built the Titanic.
Go to Top of Page

mrWize
deleted

119 Posts

Posted - 20 August 2001 :  17:09:00  Show Profile
like this:
<%
Do Until objRS.EOF
intCounter = intCounter + 1
strField = objRS("Field")
Response.Write strField
'## -- make a linebreak after every third recordset post --
If intCounter mod 3 = 0 Then Response.Write "<BR>"
objRS.MoveNext
Loop

cya,
PatrikB a.k.a mrWize

Go to Top of Page

mrWize
deleted

119 Posts

Posted - 20 August 2001 :  17:16:54  Show Profile
and if you would like to have it in a table with 3 columns:
<%
Response.Write "<TABLE><TR>"
Do Until objRS.EOF
intCounter = intCounter + 1
strField = objRS("Field")
Response.Write "<TD>" & strField & "</TD>"

If intCounter mod 3 = 0 Then Response.Write "</TR><TR>"
objRS.MoveNext
Loop

If intCounter mod 3 <> 0 Then
Do Until intCounter mod 3 = 0
REsponse.Write "<TD> </TD>"
Loop
End If
Response.Write "</TR></TABLE>"
%>

cya,
PatrikB a.k.a mrWize : http://www.mrwize.nu


Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 21 August 2001 :  04:10:59  Show Profile  Visit Kat's Homepage
Well I did post a reply at your other question. How come you didn't just reply to that with the info you posted here instead of starting another topic?

http://forum.snitz.com/forum/topic.asp?TOPIC_ID=15418

KatsKorner
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.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07