Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:52:34+00:00 2026-06-10T08:52:34+00:00

I’ve a table called mytable in my SQL SERVER database that I want to

  • 0

I’ve a table called mytable in my SQL SERVER database that I want to show into my HTML table with ASP.
here is rendered HTML table when I run SELECT * FROM mytable:
enter image description here

from that database I want to group it and change the HTML table into like this:
enter image description here
I want to eliminate the duplicate value and merge the table with rowspan.
how to loop it so it create the rowspan grouped HTML table ?

here is what I made so far:

<%
Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open Dsn

response.write "<table border='1' width='100%' cellpadding='5' cellspacing='0'>" &_
                    "<tr>" &_
                        "<td align='center' valign='middle' bgcolor='#CCCCCC'><strong>field1</strong></td>" &_
                        "<td align='center' valign='middle' bgcolor='#CCCCCC'><strong>field2</strong></td>" &_      
                        "<td align='center' valign='middle' bgcolor='#CCCCCC'><strong>field3</strong></td>" &_
                    "</tr>"

strselect = "select * from mytable"

set qdata = oConnection.execute(strselect)

If qdata.EOF then
    Response.write("NO DATA")   
Else    
    Do While Not qdata.EOF
    response.write  "<tr> " &_
                        "<td>" & trim(qdata("field1")) & "</td>"&_
                        "<td>" & trim(qdata("field2")) & "</td>"&_
                        "<td>" & trim(qdata("field3")) & "</td> " &_                            
                    "</tr>" 
    qdata.MoveNext
    Loop    
End If      

response.write "</table>"
oConnection.Close
Set oConnection = Nothing
%>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:52:35+00:00Added an answer on June 10, 2026 at 8:52 am

    This would appear to be a good time to utilize the GetRows() method of the ADO RecordSet. GetRows() converts the recordset into a multidimensional array which is then fairly trivial to walk through to compare values – an important feature in this case.

    The following code works with my test data:

    ' Assuming the connection and recordset have already been created previous to this point
    Response.Write "<table border='1' width='100%' cellpadding='5' cellspacing='0'>"
    ' Uncomment below when using the recordset
    ' Response.Write GetHeaderHtml(qdata)
    
    Response.Write "<tbody>"
    
    ' Uncomment below when using the recordset
    ' Dim rsArray : rsArray = qdata.GetRows
    ' qdata.Close
    ' oConnection.Close
    ' Set qdata = Nothing
    ' Set oConnection = Nothing
    
    ' FOR TESTING ONLY:
    Dim rsArray(2, 9)
    rsArray(0, 0) = "X1"
    rsArray(0, 1) = "X1"
    rsArray(0, 2) = "X1"
    rsArray(0, 3) = "X1"
    rsArray(0, 4) = "X1"
    rsArray(0, 5) = "X2"
    rsArray(0, 6) = "X2"
    rsArray(0, 7) = "X2"
    rsArray(0, 8) = "X2"
    rsArray(0, 9) = "X2"
    
    rsArray(1, 0) = "A"
    rsArray(1, 1) = "A"
    rsArray(1, 2) = "A"
    rsArray(1, 3) = "B"
    rsArray(1, 4) = "B"
    rsArray(1, 5) = "A"
    rsArray(1, 6) = "A"
    rsArray(1, 7) = "B"
    rsArray(1, 8) = "C"
    rsArray(1, 9) = "C"
    
    rsArray(2, 0) = "12"
    rsArray(2, 1) = "332"
    rsArray(2, 2) = "32"
    rsArray(2, 3) = "14"
    rsArray(2, 4) = "10"
    rsArray(2, 5) = "155"
    rsArray(2, 6) = "23"
    rsArray(2, 7) = "25"
    rsArray(2, 8) = "32"
    rsArray(2, 9) = "38"
    ' END TESTING DATA
    
    Dim rowHtml, occurances, row, col
    For row = LBound(rsArray, 2) To UBound(rsArray, 2)    ' the second dimension is row
      rowHtml = "<tr>"
      For col = LBound(rsArray, 1) To UBound(rsArray, 1)  ' the first dimension is column
        If row > LBound(rsArray, 2) Then
          ' previous rows written, only write out the cell if it is different than the one above.
          If rsArray(col, row) <> rsArray(col, row - 1) Then
            occurances = CountColumnOccurances(col, row, rsArray)
            ' you could probably get away writing "rowspan='1'", but I'll test for it and omit if 1
            If occurances > 1 Then
              rowHtml = rowHtml & "<td rowspan='" & CountColumnOccurances(col, row, rsArray) & "'>"
            Else
              rowHtml = rowHtml & "<td>"
            End If
            rowHtml = rowHtml & Server.HTMLEncode(rsArray(col, row))
            rowHtml = rowHtml & "</td>"
          End If
        Else
          occurances = CountColumnOccurances(col, row, rsArray)
          ' you could probably get away writing "rowspan='1'", but I'll test for it and omit if 1
          If occurances > 1 Then
            rowHtml = rowHtml & "<td rowspan='" & CountColumnOccurances(col, row, rsArray) & "'>"
          Else
            rowHtml = rowHtml & "<td>"
          End If
          rowHtml = rowHtml & Server.HTMLEncode(rsArray(col, row))
          rowHtml = rowHtml & "</td>"
        End If
      Next ' col
      rowHtml = rowHtml & "</tr>" & vbCrlf
    
      Response.Write rowHtml
    Next ' row
    Response.Write "</tbody>"
    Response.Write "</table>"
    
    Function CountColumnOccurances(curCol, curRow, arr)
      Dim occurances  : occurances = 1                  ' how many repeats
      Dim examinedRow : examinedRow = curRow + 1        ' the row we're comparing to
      Dim curValue    : curValue = arr(curCol, curRow)  ' the value were using to compare
    
      Do While examinedRow <= UBound(arr, 2)            ' the second dimension is row
        If arr(curCol, examinedRow) = curValue Then     ' the next row has the same value
          occurances = occurances + 1
        Else                                            ' the next row is different
          Exit Do
        End If
        examinedRow = examinedRow + 1
      Loop
    
      CountColumnOccurances = occurances
    End Function
    
    Function GetHeaderHtml(rsData)
      Dim strHeaders : strHeaders = "<thead><tr>"
      Dim objField
    
      For Each objField In rsData.Fields
        strHeaders = strHeaders & "<th align='center' valign='middle' bgcolor='#CCCCCC'><strong>" & objField.Name & "</strong></th>"
      Next
      strHeaders = strHeaders & "</tr></thead>"
    
      GetHeaderHtml = strHeaders
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I want to show the soap response to UIWebview.. my soap response is, <p><img
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.