|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamic table
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 Steve wrote:
Show quote > Hi All: Assuming you have a valid recordset called rs, and that you close it> > 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 > 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) & "'> </td></tr></table>" Else Response.Write "</table>" End If -- Mike Brind Mike Brind wrote:
Show quote > Steve wrote: Oops - above line should read:> > 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 > > > > 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>" Show quote Response.Write "<td>" & rs("itemID") & "</td>" |
|||||||||||||||||||||||