将数据显示为水平的ASP SQL



因此,我有一个从数据库中获得的数据,我想在ASP页面中水平显示。它就像Excel中的转置选项。

这是我的数据当前的显示方式。

Call # | Greetings # | Verifying Information # | Hold Protocol #  |
Call 1 | Greetings 1 | Verifying Information 1 | Hold Protocol  1 | 
Call 2 | Greetings 2 | Verifying Information 2 | Hold Protocol  2 |
Call 3 | Greetings 3 | Verifying Information 3 | Hold Protocol  3 |

但我想这样显示。

  Call #          | Call 1           | Call 2           | call 3
  Greeting #      | Greeting 1       | Greeting 2       | Greeting 3
  Verifying#      | Verifying 1      | Verifying 2      | Verifying 3
  Hold Protocol#  | Hold Protocol 1  | Hold Protocol 2  |  Hold Protocol 3

这是我显示数据的代码

<table class="table-striped table-bordered table-scores">
            <tr>
                <td>Call #</td>
                <td>Greetings</td>
                <td>Verifying Information</td>
                <td>Hold Protocol</td>
            </tr>
            <% 
            if not RsAgent.eof then
                do while not RsAgent.eof
            %>
                <tr>
                    <td> <% response.write("Call ") %>> </td>
                    <td> <% response.write(greeting) %> </td>
                    <td> <% response.write(verify) %> </td>
                </tr>
            <%  
                    ctr =ctr+1
                    RsAgent.movenext
                    loop
                    end if 
                end if  
            %>
        </table>

您可以使用getrows RecordSet的方法将记录检索到数组中,然后按照您的意愿打印数据。

这是一个例子:

<table>
<%
  titles = Array("Call #", "Greetings #", "Verifying Information #", "Hold Protocol #")
  data = rsAgent.GetRows()
  For i=0 To 3
%>
    <tr>
      <th><%=titles(i)%></th>
    <% For j=0 To UBound(data,2) %>
      <td><%=data(i,j)%></td>
    <% Next j %>
    </tr>
<% Next i %>
</table>

您可能想做的是这样的事情。

<tr>
    <td>Call#</td>
<% while not RsAgent.eof %>
    <td><% response.write("call") %></td>
<% RsAgent.movenext %>
<% wend %>
</tr>
<% RsAgent.movefirst %>
<tr>
    <td>Greetings</td>
<% while not RsAgent.eof %>
    <td><% response.write("greeting") %></td>
<% RsAgent.movenext %>
<% wend %>
</tr>

等...

最新更新