The best method to list by columns from a db

Discussion in 'ASP General' started by PiGei, Apr 18, 2005.

  1. PiGei

    PiGei Guest

    hi all,
    I'm using the following code to read articles from a db and show them by
    columns and not by rows.
    I think the code could be better... so, if you have some advice...

    thanks

    db= access

    <%
    Dim num_col 'number of columns
    Dim end_row 'checking enf of row
    Dim counter

    num_col = 2
    end_row = "false"
    counter = 1
    %>

    <table border="1" cellpadding="2" cellspacing="2" width="450">
    <%
    Do While Not rstSimple.EOF
    %>
    <%
    If end_row = "false" Then
    response.write "<tr>"
    End If
    %>
    <td>
    <%= rstSimple.Fields("id").Value %><br>
    <%= rstSimple.Fields("titolo").Value %><br>
    <%= rstSimple.Fields("data").Value %><br>
    <%= "end_row= " & end_row %><br>
    <%= "counter= " & counter %><br>
    <%= "num_col= " & num_col %><br>
    </td>
    <%
    rstSimple.MoveNext
    %>
    <%
    If counter = num_col OR rstSimple.EOF Then
    response.write "</tr>"
    end_row = "false"
    counter = 1
    %>
    <%
    Else
    %>
    <% counter = counter+1 %>
    <% end_row = "true" %>
    <% End If %>
    <%
    Loop
    %>
    </table>

    Thanks
     
    PiGei, Apr 18, 2005
    #1
    1. Advertising

  2. PiGei wrote:
    > hi all,
    > I'm using the following code to read articles from a db and show them
    > by columns and not by rows.
    > I think the code could be better... so, if you have some advice...


    You might want to consider using GetRows():
    http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthgetrows.asp


    This is why (thanks to ASP FAQ):

    "By its very nature, the 2-dimensional array returned by the GetRows
    method is non-linear. This has important implications for the ways
    in which the result set data can be processed. The data in the result
    set can be processed in a row-by-row, column-by-column or cell-by-cell
    manner, or any combination there-of. Formatting can also take place at
    the row, column and/or cell level."

    http://aspfaq.com/show.asp?id=2467



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Apr 18, 2005
    #2
    1. Advertising

  3. PiGei

    PiGei Guest

    Thanks
    PGei

    "Dave Anderson" <> wrote in message
    news:%...
    > PiGei wrote:
    >> hi all,
    >> I'm using the following code to read articles from a db and show them
    >> by columns and not by rows.
    >> I think the code could be better... so, if you have some advice...

    >
    > You might want to consider using GetRows():
    > http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthgetrows.asp
    >
    >
    > This is why (thanks to ASP FAQ):
    >
    > "By its very nature, the 2-dimensional array returned by the GetRows
    > method is non-linear. This has important implications for the ways
    > in which the result set data can be processed. The data in the result
    > set can be processed in a row-by-row, column-by-column or cell-by-cell
    > manner, or any combination there-of. Formatting can also take place at
    > the row, column and/or cell level."
    >
    > http://aspfaq.com/show.asp?id=2467
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.
    > Use of this email address implies consent to these terms. Please do not
    > contact me directly or ask me to contact you directly for assistance. If
    > your question is worth asking, it's worth posting.
    >
     
    PiGei, Apr 18, 2005
    #3
  4. PiGei wrote:
    > hi all,
    > I'm using the following code to read articles from a db and show them
    > by columns and not by rows.
    > I think the code could be better... so, if you have some advice...
    >
    > thanks
    >
    > db= access
    >
    > <%
    > Dim num_col 'number of columns
    > Dim end_row 'checking enf of row
    > Dim counter
    >
    > num_col = 2
    > end_row = "false"
    > counter = 1
    > %>
    >
    > <table border="1" cellpadding="2" cellspacing="2" width="450">
    > <%
    > Do While Not rstSimple.EOF
    > %>
    > <%
    > If end_row = "false" Then
    > response.write "<tr>"
    > End If
    > %>
    > <td>
    > <%= rstSimple.Fields("id").Value %><br>
    > <%= rstSimple.Fields("titolo").Value %><br>
    > <%= rstSimple.Fields("data").Value %><br>
    > <%= "end_row= " & end_row %><br>
    > <%= "counter= " & counter %><br>
    > <%= "num_col= " & num_col %><br>
    > </td>
    > <%
    > rstSimple.MoveNext
    > %>
    > <%
    > If counter = num_col OR rstSimple.EOF Then
    > response.write "</tr>"
    > end_row = "false"
    > counter = 1
    > %>
    > <%
    > Else
    > %>
    > <% counter = counter+1 %>
    > <% end_row = "true" %>
    > <% End If %>
    > <%
    > Loop
    > %>
    > </table>
    >
    > Thanks


    This should be better:
    <%
    Dim num_col 'number of columns
    dim iRows, iRow
    Dim iCol
    dim arData, i, j
    dim arHTML(), sHTML, sCell

    num_col = 2
    arData = rstSimple.GetRows

    rstSimple.close:set rstSimple=nothing
    'close and destroy your connection here as well

    if isArray(arData) then
    sHTML = "<TABLE border=""1"" cellpadding=""2""" & _
    " cellspacing=""2"" width=""450"">"
    iRows = ubound(arData,2) \ num_col
    if ubound(arData,2) mod num_col > 0 then iRows = iRows+1
    reDim arHTML(iRows)
    for i = 0 to ubound(arData,2)
    iCol= (i mod num_col) + 1
    iRow=(i \ num_col) + 1
    if iCol = 1 then
    sCell = "<TR><TD>"
    elseif sCol < num_col then
    sCell=sCell & "<TD>"
    end if
    sCell=sCell & arData(0,i)
    for j=1 to 2
    sCell = sCell & "<BR>" & arData(j,i)
    next
    sCell = sCell & "<BR>Column= " & iCol
    sCell = sCell & "<BR>Row= " & iRow & "</TD>"
    if iCol = num_col then
    arHTML(iRow - 1) = sCell & "</TR>"
    elseif i = ubound(arData,2) then
    do until iCol = num_col
    sCell = sCell & "<TD> &nbsp;</TD>"
    iCol=iCol+1
    loop
    arHTML(iRow - 1) = sCell & "</TR>"
    end if
    next
    sHTML = sHTML & join(arHTML,vbCrLf) & "</TABLE>"
    else
    sHTML = "No data was returned"
    end if
    Response.Write sHTML
    %>

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Apr 18, 2005
    #4
  5. PiGei

    PiGei Guest

    Thanks Bob
    PGei

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > PiGei wrote:
    >> hi all,
    >> I'm using the following code to read articles from a db and show them
    >> by columns and not by rows.
    >> I think the code could be better... so, if you have some advice...
    >>
    >> thanks
    >>
    >> db= access
    >>
    >> <%
    >> Dim num_col 'number of columns
    >> Dim end_row 'checking enf of row
    >> Dim counter
    >>
    >> num_col = 2
    >> end_row = "false"
    >> counter = 1
    >> %>
    >>
    >> <table border="1" cellpadding="2" cellspacing="2" width="450">
    >> <%
    >> Do While Not rstSimple.EOF
    >> %>
    >> <%
    >> If end_row = "false" Then
    >> response.write "<tr>"
    >> End If
    >> %>
    >> <td>
    >> <%= rstSimple.Fields("id").Value %><br>
    >> <%= rstSimple.Fields("titolo").Value %><br>
    >> <%= rstSimple.Fields("data").Value %><br>
    >> <%= "end_row= " & end_row %><br>
    >> <%= "counter= " & counter %><br>
    >> <%= "num_col= " & num_col %><br>
    >> </td>
    >> <%
    >> rstSimple.MoveNext
    >> %>
    >> <%
    >> If counter = num_col OR rstSimple.EOF Then
    >> response.write "</tr>"
    >> end_row = "false"
    >> counter = 1
    >> %>
    >> <%
    >> Else
    >> %>
    >> <% counter = counter+1 %>
    >> <% end_row = "true" %>
    >> <% End If %>
    >> <%
    >> Loop
    >> %>
    >> </table>
    >>
    >> Thanks

    >
    > This should be better:
    > <%
    > Dim num_col 'number of columns
    > dim iRows, iRow
    > Dim iCol
    > dim arData, i, j
    > dim arHTML(), sHTML, sCell
    >
    > num_col = 2
    > arData = rstSimple.GetRows
    >
    > rstSimple.close:set rstSimple=nothing
    > 'close and destroy your connection here as well
    >
    > if isArray(arData) then
    > sHTML = "<TABLE border=""1"" cellpadding=""2""" & _
    > " cellspacing=""2"" width=""450"">"
    > iRows = ubound(arData,2) \ num_col
    > if ubound(arData,2) mod num_col > 0 then iRows = iRows+1
    > reDim arHTML(iRows)
    > for i = 0 to ubound(arData,2)
    > iCol= (i mod num_col) + 1
    > iRow=(i \ num_col) + 1
    > if iCol = 1 then
    > sCell = "<TR><TD>"
    > elseif sCol < num_col then
    > sCell=sCell & "<TD>"
    > end if
    > sCell=sCell & arData(0,i)
    > for j=1 to 2
    > sCell = sCell & "<BR>" & arData(j,i)
    > next
    > sCell = sCell & "<BR>Column= " & iCol
    > sCell = sCell & "<BR>Row= " & iRow & "</TD>"
    > if iCol = num_col then
    > arHTML(iRow - 1) = sCell & "</TR>"
    > elseif i = ubound(arData,2) then
    > do until iCol = num_col
    > sCell = sCell & "<TD> &nbsp;</TD>"
    > iCol=iCol+1
    > loop
    > arHTML(iRow - 1) = sCell & "</TR>"
    > end if
    > next
    > sHTML = sHTML & join(arHTML,vbCrLf) & "</TABLE>"
    > else
    > sHTML = "No data was returned"
    > end if
    > Response.Write sHTML
    > %>
    >
    > HTH,
    > Bob Barrows
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    >
     
    PiGei, Apr 18, 2005
    #5
    1. Advertising

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. helpful sql
    Replies:
    0
    Views:
    849
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    632
  3. Replies:
    4
    Views:
    963
  4. =?Utf-8?B?YmVub2l0?=

    Read CSV - string Columns - Int columns

    =?Utf-8?B?YmVub2l0?=, May 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    452
    =?Utf-8?B?YmVub2l0?=
    May 8, 2006
  5. Jacksm
    Replies:
    2
    Views:
    890
    Paul Chalekian
    Nov 21, 2006
Loading...

Share This Page