Dynamic table

Discussion in 'ASP General' started by Steve, May 19, 2006.

  1. Steve

    Steve Guest

    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
     
    Steve, May 19, 2006
    #1
    1. Advertisements

  2. Steve

    Mike Brind Guest

    Steve wrote:
    > 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>"
    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
     
    Mike Brind, May 19, 2006
    #2
    1. Advertisements

  3. Steve

    Mike Brind Guest

    Mike Brind wrote:
    > Steve wrote:
    > > 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>"


    Oops - above line should read:
    Response.Write "<td>" & rs("itemID") & "</td>"
     
    Mike Brind, May 19, 2006
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Glos
    Replies:
    0
    Views:
    701
    Rick Glos
    Jul 8, 2003
  2. David Williams
    Replies:
    2
    Views:
    1,227
    Jacob Yang [MSFT]
    Aug 12, 2003
  3. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    786
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
  4. opius
    Replies:
    0
    Views:
    1,234
    opius
    Jun 17, 2011
  5. Kooki

    Dynamic Table with Dynamic Button inside

    Kooki, Sep 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    190
    Kooki
    Sep 15, 2005
Loading...

Share This Page