sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Bennie Sanders's Avatar

Formatting columns with dynamic data


Question posted by: Bennie Sanders (Guest) on July 19th, 2005 12:50 PM

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.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
2 Answers Posted
William Morris's Avatar
William Morris July 19th, 2005 12:50 PM
Guest - n/a Posts
#2: Re: Formatting columns with dynamic data

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


--
William Morris
Semster, Seamlyne reProductions
Visit our website, http://www.seamlyne.com, for the most comfortable
historically inspired clothing you can buy!

"Bennie Sanders" <bennie@clickfocal.com> wrote in message
news:uEchRZxGEHA.2844@tk2msftngp13.phx.gbl...[color=blue]
>
> 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.
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


John Hoge's Avatar
Guest - n/a Posts
#3: Re: Formatting columns with dynamic data

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.
 
Not the answer you were looking for? Post your question . . .
197,007 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,007 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors