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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Single Field across two columns? 2

Status
Not open for further replies.

waidc

Technical User
Mar 7, 2001
23
NZ
Hopefully someone can assist me with this, I've searched all over and other than an inkling that maybe a counter is required I've drawn a blank.

Basically from an access database comes a list of schools and their details. At the top of the asp page is the list of all schools with links to the details further down the page.

Rather than have the school names at the top run on from each other, I'd like them to be in two columns but am unsure how to split a single field (school_name) into two columns.


<table>
<tr><td width="50%">
<a href="#<%=(rs.Fields("school_name").Value)%>">
<%=(rs.Fields("school_name").Value)%></a></td>
<td></td></table>

<%
rs.MoveNext
loop%><table>
<tr><td width="50%">
<a href="#<%=(rs.Fields("school_name").Value)%>">
<%=(rs.Fields("school_name").Value)%></a></td>
<td></td></table>

<%
rs.MoveNext
loop%>

Any assistance would be gratefully received. Many thanks
 
apologies - the code has printed twice - here is the code as it stands:

<table>
<tr><td width="50%">
<a href="#<%=(rs.Fields("school_name").Value)%>">
<%=(rs.Fields("school_name").Value)%></a></td>
<td></td></table>

<%
rs.MoveNext
loop%>
 
I would use Getrows function (see for an example), add one more element (empty string) to the array if required to make the count even. Getrows provides a zero-based array, so make Ubound odd.
Then loop through the array using LBound and Ubound for your loop limits with a Step value of 2. Your loop will look something like this pseudocode assuming you're only pulling a single field in your recordset:
Code:
<table>
<% For a = 0 to Ubound(myArray) Step 2 %>
<tr><td><%=(myArray(a)%></td>
<td><%=(myArray(a + 1)%></td></tr>
<% Next %>
</table>
It will of course be a bit tidier if you do it all with Response.Write for the HTML bits

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
To add to John's excellent suggestion, there is a function specifically designed for this type of scenario, and as such is usually the most performant:


getstring will return the data formatted as a string just how you want to display it. It's not ideal for every situation, as it does limit what you can do conditionally within the string based on the array values. however if you just want to create table td's/tr's then this will likely be the most efficient way to do it.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top