Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 19th, 2006, 01:05 AM
Steve
Guest
 
Posts: n/a
Default Dynamic table

Hi All:

I've managed to get myself into something I thought would be simple, and is
turning out not to be, or I am too close to the trees to see the forest.

I am creating a recordset from a table in an access database using classic
ASP.

I now need to display the database in a table in a web page, which is
normally simple enough, but the twist is I need to display the items in
order in a fixed number of columns (4) and the number of rows are determined
dynamically in itemID order going from left to right. For instance:
itemID1 itemID2 itemID3 ItemID4
itemID5 itemID6 itemID7 itemID8

I have some code that will display this data like this:
itemID1 itemID3 itemID5 ItemID7
itemID2 itemID4 itemID6 itemID8
however, this does not work for this project.

This is the code I am using to create the second layout...could anyone take
a look to see what I can do to get the required result?

intColumns = 4
response.write "recCount=" & objRs.RecordCount & "
"
response.write "rows=" & objrs.RecordCount * ((i+1)/(intColumns)) & "
"

redim ColumnArray(intColumns-1)

for i = 0 to ubound(ColumnArray)
ColumnArray(i) = objrs.RecordCount * ((i+1)/(intColumns))
next

redim DataArray(objrs.RecordCount/(intColumns-1),intColumns)

for i = 0 to intColumns-1
k = 0
do while j < ColumnArray(i)
DataArray(k,i) = objRs("itemID")
j = j + 1
k = k + 1
objrs.MoveNext
loop
next

<table border=1 width=600 align=center>
<%
for i = 0 to ubound(DataArray)
Response.Write("<tr>")
for j = 0 to intColumns - 1
Response.Write("<td>")
if DataArray(i,j) <> "" then
Response.Write(DataArray(i,j))
else
Response.Write(" ")
end if

Response.Write("</td>")
next

Response.Write("</tr>")

txtContinue = ""
for j = 0 to intColumns
txtContinue = txtContinue & DataArray(i+1,j)
next
if txtContinue = "" then Exit For end if
next

%>
</table>

Thanks

Steve


  #2  
Old May 19th, 2006, 02:05 PM
Mike Brind
Guest
 
Posts: n/a
Default Re: Dynamic table


Steve wrote:[color=blue]
> Hi All:
>
> I've managed to get myself into something I thought would be simple, and is
> turning out not to be, or I am too close to the trees to see the forest.
>
> I am creating a recordset from a table in an access database using classic
> ASP.
>
> I now need to display the database in a table in a web page, which is
> normally simple enough, but the twist is I need to display the items in
> order in a fixed number of columns (4) and the number of rows are determined
> dynamically in itemID order going from left to right. For instance:
> itemID1 itemID2 itemID3 ItemID4
> itemID5 itemID6 itemID7 itemID8
>[/color]

Assuming you have a valid recordset called rs, and that you close it
properly at the end...

Dim i
i = 0
Response.Write "<table>"

Do Until rs.EOF
i = i + 1
if i mod 4 = 1 then Response.Write "<tr>"
Response.Write "<td>" & i & "</td>"
if i mod 4 = 0 then Response.Write "</tr>"
rs.Movenext
Loop

If i mod 4 > 0 then
Response.Write "<td colspan='" & 4 - (i mod 4) &
"'>&nbsp;</td></tr></table>"
Else
Response.Write "</table>"
End If

--
Mike Brind

  #3  
Old May 19th, 2006, 02:15 PM
Mike Brind
Guest
 
Posts: n/a
Default Re: Dynamic table


Mike Brind wrote:[color=blue]
> Steve wrote:[color=green]
> > Hi All:
> >
> > I've managed to get myself into something I thought would be simple, and is
> > turning out not to be, or I am too close to the trees to see the forest.
> >
> > I am creating a recordset from a table in an access database using classic
> > ASP.
> >
> > I now need to display the database in a table in a web page, which is
> > normally simple enough, but the twist is I need to display the items in
> > order in a fixed number of columns (4) and the number of rows are determined
> > dynamically in itemID order going from left to right. For instance:
> > itemID1 itemID2 itemID3 ItemID4
> > itemID5 itemID6 itemID7 itemID8
> >[/color]
>
> Assuming you have a valid recordset called rs, and that you close it
> properly at the end...
>
> Dim i
> i = 0
> Response.Write "<table>"
>
> Do Until rs.EOF
> i = i + 1
> if i mod 4 = 1 then Response.Write "<tr>"
> Response.Write "<td>" & i & "</td>"[/color]

Oops - above line should read:
Response.Write "<td>" & rs("itemID") & "</td>"

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

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 205,338 network members.