Formatting columns with dynamic data

B

Bennie Sanders

Hi there,

I have a SQL 2000 table with data I display in three columns. The code
I am using sorts the data horizontally but I need it sorted vertically.
Here's the code I am using. Perhaps somebody can help me find a way to
modify it.


CODE
response.write "<table width='100%' cellpadding=1 cellspacing=0>"
if not oMain.eof then
count = 0
do while not oMain.eof
if count mod 3 = 0 then
'there are 3 in the current row, so end the row and start a new
one...
response.write "</tr><tr>"
end if

'add the item number to another column
response.write "<td valign=top><ul><li>" & oMain("catcode")

'increment the count
count = count+1

oMain.MoveNext
loop
Response.Write "</table>"
end if

It's displaying 1 2 3 across instead of down and starting the next
column with 4. I hope I am making sense. Thank you very much.
 
W

William Morris

If you translate your recordset into an array then you can loop through the
indexes any way you like. Usually, row column output works this way:

for rCounter = 0 to ubound(myArray, 2)
response.write "<tr>"
for cCounter = 0 to ubound(myArray)
response.write "<td>" & myArray(cCounter, rCounter) & "</td>"
next
response.write "</tr>"
next

Seems to me you could swap the two loops, so:

for cCounter = 0 to ubound(myArray)
response.write "<tr>"
for rCounter = 0 to ubound(myArray, 2)
response.write "<td>" & myArray(cCounter, rCounter) & "</td>"
next
response.write "</tr>"
next

Haven't tried it, but that'd be my first inclination.

- Wm
 
J

John Hoge

Bernie,

Your script will output the recordset in the following manner:

123
456
789

Do you want it to do this?

147
258
369

If so, you have a few options:
1) You can use a stored procedure to order your recordset this way, if
your DB is SQL Server. This will be the most efficient.
2) you can use the .move method of the recordset object to more the
cursor forward and backward to reorder the data using ADO. It makes
for busy code, but it works.
3) You can use the .getrows method of the recordset object to make an
array. This is probably faster than method two, but also somewhat
busy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top