Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a recordset into columns

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
GB
Hi

I am returning a recordset that has around 100 records. This should not vary by more than 20 either way. I want to create a check box for each record:
Code:
Response.Write "<td><small><INPUT NAME=""EmailXtra"" TYPE=""CHECKBOX"" VALUE=" & rs.fields.item("Email").Value & ">" & rs.fields.item("UserFullName").Value & "</small></td>"
Is it possible to split these into columns as in
<td>25 records</td><td>25 records</td><td>25 records</td><td>25 records</td>

Or even better, to total the number of records and divide by 4 to create an even column layout.

Thanks

Jonathan
 
you need to count the records and divide by four to get the total number of records per column.

Then start a loop keeping track of the total number of records in a counter, resetting it to 1 each time it reaches the value of the total number of columns.

At this point, close the "<td>" and start a new one.

Once you are done, check the value of the counter to see if you have to close the final "<td>"


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
You should be able to do this.

Look at rs.RecordCount as one way to get your record count. Divide it by 4 to get your number of records in each column. That division will need some correction and rounding.

Can't go much further with code until we know if there is order in the records. If there is order do you want things to look like

147
258
369

or

123
456
789

??
 
Guys

Thanks for your responses, and apologies for not replying sooner (Just had a weekend without any screens!).

After I had posted the question I found a suitable answer on Google and both of you were in the right ball park:

I post my solution here for others to see and use.
Code:
<% nCount = 0 %>
<table border="1">
<%
	Do while Not rs.eof
		nCount = nCount + 1
		If nCount Mod 5 = 1 Then
			' put in a <tr>
			%>
			<tr align="left">
			<%
			End If
			%>
		<%if rs("IsChecked") = 0 then 
		response.Write "<td><small><INPUT NAME=""EmailXtra"" TYPE=""CHECKBOX""  VALUE=" & rs("Email") & ">" & rs("UserFullName") & "</small></td>"
		else
		Response.write"<td style=""background-color: #EBDDE2;""><small>" & rs("UserFullName") & "</small></td>"
		end if %>
			<%
		If nCount Mod 5 = 0 Then
			' put in a </tr>
			%>
			</tr>
			<%  
			End If
			rs.MoveNext
			Loop
		' see if we need a final </tr>
			If nCount Mod 5 > 0 Then
			%>
			</tr>
			<%
		End If
		%>
</table>
In this case it gives me 5 columns (mod 5).

Thanks again, this must be the best 'help' site around, I rarely fail to find answers on here.

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top