显示数据到表格水平asp sql

时间:2014-03-06 16:36:24

标签: sql asp-classic

所以我有一个从数据库中获取的数据,我希望在我的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>

2 个答案:

答案 0 :(得分:1)

您可以使用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>

答案 1 :(得分:0)

你可能想要做的就是这样。

<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>

依旧......