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.

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


Any assistance would be gratefully received. Many thanks :)

It seems that a simple 'colspan=2' would do the trick.

<td colspan=2>Some Text</td>


Unfortunately no - I want to do the opposite of colspan.

I have currently a single column of names that I want to split into two columns, whereas colspan would work if it were the other way around.

Thanks for the suggestion though - any advice has got to be good :)

OHHhhh! Ok, I understand what you're getting at.

Well, there are a few ways to tackle that problem.

But here is my best solution. Get the recordset, divide the recordcount by two, fill two dynamic arrays, then fill the table.

'open the recordset (however you do it)

'get the count
5RCount = (RCount/2)

' Dimension the dynamic arrays
reDim array1(5RCount)
reDim array2(5RCount)

' Fill the arrays
For a = 1 to 5RCount
  array1(a) = RS("Name")

For b = 5RCount + 1 to RCount
  array1(a) = RS("Name")

'Show the data
for i = 1 to ubound(array1)
    <td><% =array1(i) %></td><td><% =array2(i) %></td>

NOTE: For recordsets with ODD numbers, you may need to do some other manipulations to get the data show up correctly.

HTH, Good Luck!!

Thanks so much for your help and the code.

It certainly looks logical and I can follow what it's meant to be doing, but I'm getting errors all over the place when I try and implement it so after several hours of attempting to get it working I'm conceding defeat.

I can use static html to fill in what I need, given the limited number of schools and the fact that it's unlikely too many more will open in years to come. Disappointed I couldn't get it to work though as it looked like a great solution.

Thanks again Certguard

Wow, yeah, I really blew that one out of the water, didn't I ?!

My apologies. That'll be the last time I punch out a block of code in a hurry. Don't give up yet though, if it's one thing I've learned about computers (and this is the reason I'm a programmer) it's that you can make a computer do anything you want it to (within reason, of course)

I may as well explain the mistakes made earlier, but first, here is a working block of code.

dbpath = server.mappath("myDatabase.mdb")

strSQL = "SELECT Name FROM [table] ORDER BY Name"

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open strSQL, Conn, 1, 3

'get the count
R5Count = cint(RCount/2)

' Dimension the dynamic arrays
reDim array1(R5Count)
reDim array2(R5Count)

' Fill the arrays
For a = 1 to R5Count
  array1(a) = RS("Name")

For b = 1 to R5Count
  array2(b) = RS("Name")

'Show the data
%><table border = 1><%
for i = 1 to ubound(array1)
    <td><% =array1(i) %></td><td><% =array2(i) %></td>

THAT, I'm hoping will get you the results you're looking for. Here is a working example with data from my DB: http://www.certguard.com/splitColumn.asp

Now to explain the errors I created with the earlier mistakes.

1. Variables cannot start with numbers
2. Close all FOR loops with a Next statement
3. HTML Tags belong on the right of %>

What you could also do which requires not using two different arrays and using your current code:


Dim i = 0
Do While Not rs.EOF
  if i = 2 then
    i = 0
  end if
  response.write("<td width=""50%"">")
  response.write("<a href=""#" & rs.Fields("school_name").Value """>")
  i = i + 1

if i = 1 then response.write("<td></td>")

What this does is first write the beginning of the table, then does the loop twice. When the loop then goes a third time, it writes a new row and sets the integer back to zero to redo the counts. If you have an odd number of records, it will write another column block then close the table. Simple and effective. Enjoy

Good solution. A few minor errors, but nothing as bad as mine was. ;)

The only difference in the final result is the way the list is presented.

A, C
B, D


A, B
C, D

yup. This all depends on how you would like it, and whether it matters. If you wish to have it listed vertically, then follow the previous example. Horizontally, follow mine. If it doesn't matter, find out what works for you

Much kudos to you both for your most excellent suggestions - they now work so well (I even managed to work out how to fix data with apostrophes in it myself).

Having tried and tested both solutions I'm very happy with the result - I'm surprised there wasn't really anything like this already on the internet (at least from Google searches) as I'm sure others must have come across this issue too - of course, they could be better at programming than I!!

Thanks again CertGuard and SheSaidImaPregy - A+++++

This article has been dead for over six months. Start a new discussion instead.