4 cell table

1. Senior Member
Join Date
Dec 1969
Posts
124

## 4 cell table

Hello everyone. - Let&#039;s get right down to it<BR><BR>After I select my records from a table I throw them into an array. Then I run a loop displaying my records into 4 cells. I wrote this<BR><BR>&#060;%<BR>For i = 0 to ubound(ar,2) step 4<BR>%&#062;<BR> &#060;tr&#062;<BR> &#060;td width="25%"&#062;<BR>&#060;%<BR>If i &#062; ubound(ar,2) then<BR> Response.Write "&nbsp;"<BR>Else<BR> Response.Write "&#060;a href=""findword2.asp?ID=" & ar(2,i) & """&#062;" & ar(0,i) & "&#060;/a&#062;"<BR>End If<BR>%&#062;<BR>&#060;/td&#062;<BR> &#060;td width="25%"&#062;<BR>&#060;%<BR>If i+1 &#062; ubound(ar,2) then<BR> Response.Write "&nbsp;"<BR>Else<BR> Response.Write "&#060;a href=""findword2.asp?ID=" & ar(2,i+1) & """&#062;" & ar(0,i+1) & "&#060;/a&#062;"<BR>End If<BR>%&#062;<BR>&#060;/td&#062;<BR> &#060;td width="25%"&#062;<BR>&#060;%<BR>If i+2 &#062; ubound(ar,2) then<BR> Response.Write "&nbsp;"<BR>Else<BR> Response.Write "&#060;a href=""findword2.asp?ID=" & ar(2,i+2) & """&#062;" & ar(0,i+2) & "&#060;/a&#062;"<BR>End If<BR>%&#062;<BR>&#060;/td&#062;<BR> &#060;td width="25%"&#062;<BR>&#060;%<BR>If i+3 &#062; ubound(ar,2) then<BR> Response.Write "&nbsp;"<BR>Else<BR> Response.Write "&#060;a href=""findword2.asp?ID=" & ar(2,i+3) & """&#062;" & ar(0,i+3) & "&#060;/a&#062;"<BR>End If<BR>%&#062;<BR>&#060;/td&#062;<BR> &#060;/tr&#062;<BR>&#060;%<BR>Next<BR>%&#062;<BR><BR>It works fine, but I was wondering if there was a more efficient way of writing this. I was thinking of a sub routine using strcat.catter Anyone have any ideas that could lead me in the right direction. <BR><BR>Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
623

## RE: 4 cell table

*******************************************<BR>SET rs = conn.Execute(sql) <BR>ar = rs.getRows() <BR>rs.close() <BR>SET rs = nothing <BR><BR>for iLoop = 0 to UBound(ar,2) <BR> if (iLoop MOD 4 = 0) THEN <BR> Response.Write("&#060;tr&#062;") <BR> end if <BR> Response.Write("&#060;td&#062;" & allThatYouNeedToDisplay & "&#060;/td&#062;") <BR> if (iLoop MOD 4 = 3) THEN <BR> Response.Write("&#060;/tr&#062;") <BR> end if <BR>next<BR>************************************** *****<BR>you will have to tweak it around a bit, but much cleaner and lesser content switching

3. Senior Member
Join Date
Dec 1969
Posts
124

## Thanks...

a million. That&#039;s exactly what I was looking for. Hope you had a good Easter. I spent mine coding, but when you do what you love then I guess it ain&#039;t so bad. :)

4. Senior Member
Join Date
Dec 1969
Posts
124

## Problem

Ok that would be great if I only had 4, 8 12, etc... number of records. If I have 13 records I would get an error when iLoop is = to 13. You see a way around that?

5. Senior Member
Join Date
Dec 1969
Posts
623

## RE: Problem

wouldn&#039;t be a problem except for the fact that you will miss a &#060;tr&#062; tag at the end, well you could do a <BR>*********************************<BR>if (UBound(ar) MOD 4 &#060;&#062; 3) then<BR> Response.Write("&#060;tr&#062;")<BR>end if<BR>*********************************<BR>after the next i guess<BR><BR>&#062;I would get an error when iLoop is = to 13<BR>what error are you talking about?

6. Senior Member
Join Date
Dec 1969
Posts
623

## RE: Thanks...

Learning .net at home, so didn&#039;t hav too much fun :(

7. Senior Member
Join Date
Dec 1969
Posts
124

## RE: Problem

ok you&#039;re right. There wouldn&#039;t be an error but we would have a collapsed cell. Is there a way to avoid that? My customer is really stuck on having table and cell borders.

8. Senior Member
Join Date
Dec 1969
Posts
124

## BTW...

What are doing up so late? I thought I was the only that hit the message board at this hour.

9. Senior Member
Join Date
Dec 1969
Posts
124

## Step Back

I think we missed the whole point of the post. <BR><BR>What you gave me on your first reply only puts one record per row. What I am after is 4 records per row. I am gonna see if I can&#039;t tweak what I got from you so far. I am gonna go for the night but finish up what I am working on right now. Thanks for your help.<BR><BR>

10. Senior Member
Join Date
Dec 1969
Posts
623

## those doggone clients...

SET rs = conn.Execute(sql) <BR>ar = rs.getRows() <BR>rs.close() <BR>SET rs = nothing <BR><BR>for iLoop = 0 to UBound(ar,2) <BR> if (iLoop &#060;&#062; 0) THEN Response.Write("&#060;/tr&#062;") & vbcrlf<BR> if (iLoop MOD 4 = 0) THEN Response.Write("&#060;tr&#062;") & vbcrlf<BR> Response.Write("&#060;td&#062;" & allThatYouNeedToDisplay & "&#060;/td&#062;") & vbcrlf<BR>next <BR>var howManyRows = 3 - UBound(ar)<BR>Response.Write(Replace(Space(howMany Rows), " ", "&#060;td&#062;&nbsp;&#060;/td&#062;"))<BR>Response.Write("&#060;/tr&#062;")

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•