Click to See Complete Forum and Search --> : Problem with adding a BR for each 4 records


weee
03-30-2006, 02:36 PM
I'm tryin to add a <TR> every time I have 4 <TD> and I think I'm missing something.

My code:


<table>
<tr>
<%
SQL = "SELECT color FROM productsTBL"
rs.Open SQL,DSN,3,1
If NOT rs.eof Then
For i=1 To numFiles
If i mod 4 Then
tr = ""
Else
tr = "</tr>"
End If
Next
Do Until rs.eof
%>
<a href="<%=rs("id")%>"><%=rs("id")%></a>
<%
rs.moveNext
loop

response.write tr
End If
%>
</tr>
</table>


What's missing there in order to get it working?

milo
03-30-2006, 03:16 PM
Forgive me if I am off base - I don't use the mod function all that often, but it returns a remainder doesn't it? So I think that you'd want to use:

For i=1 To numFiles
If i mod 4 <> 0 Then
tr = ""
Else ' i is evenly divisible by 4, so write </tr>
tr = "</tr>"
End If
Next

Is this incomplete code tho? I didn't see any <td>'s in there, and if you're starting a new row, you would need to open a <tr> as well. Hope that helps.

lmf232s
03-30-2006, 04:47 PM
use
i mod 5
instead of i mod 4.

Your starting at 1. Your code should work if you were starting at 0.

Ubik
04-09-2006, 03:11 PM
<table>
<tr>
<%
SQL = "SELECT color FROM productsTBL"
rs.Open SQL,DSN,3,1
If NOT rs.eof Then
For i=1 To numFiles
If i mod 4 Then
tr = ""
Else
tr = "</tr><tr>"
End If
Next
Do Until rs.eof
%>
<td><a href="<%=rs("id")%>"><%=rs("id")%></a></td>
<%
response.write tr
rs.moveNext
loop


End If
%>
</tr>
</table>