打印本文 打印本文  关闭窗口 关闭窗口
如何使用ASP在自己的网站建立投票机制(一)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 13:43:26
ot;)
   conn.open dsnpath
   Set rs = Conn.Execute(sql)
   If rs.EOF = False Then
%>
  <table border=1 cellspacing=0 cellpadding=5 width=500 bordercolor=#2f2f4f><tr>
  <td colspan=3 bgcolor=#2f2f4f align=center><font face="verdana" color=#f5fcdc>
   <%=rs("PollQuestion")%>
  </td></tr>
   <%
      Dim Choices(6)
      Dim Responses(6)
      For I=1 To 5
          choice = rs("Choice" & I)
          Choices(I) = choice
          If choice <> "" Then
              Set conn2 = Server.CreateObject("ADODB.Connection")
              sql = "select COUNT(PollAnswer) from PollResults where PollID = " & Cint(id) & " AND PollAnswer=" & I
            dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
              dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
              conn2.open dsnpath
              Set rs2 = Conn.Execute(sql)
              If rs2.EOF = False Then
                 Response.Write "<tr><td colspan=2 bgcolor=#4f4f4f align=center width=400><font face='verdana' color=#f5fcdc>"
                 Response.Write choice
                 Response.Write "</td>"
                 Responses(I) = rs2(0)
                 Response.Write "<td colspan=1 bgcolor=#4f4f4f align=right><font face='verdana' color=#f5fcdc><b>" & rs2(0) & "</b></td>"
                 Response.Write "</tr>"
              End If
              rs2.Close
              conn2.Close
          End If
      Next
    End If
   %>

</table>

<br><br>

<table >
<td colspan=3  align=center><font face="arial">
   <font face="ms sans serif"><b> Polls Results</b></font>
  </td></tr>

<%
      Total = 0
      For I=1 To 5
          responseCount = Responses(I)
          If responseCount <> "" Then
                 Total = Total + Cint(responseCount)
          End If
      Next
      For I=1 To 5
          choice = Choices(I)
          responseCount = Responses(I)
          If choice <> "" Then
                 Response.Write "<tr><td colspan=1 align=left><font face='arial'>"
                 Response.Write choice
                 Response.Write "</td>"
                 Response.Write "<td colspan=2 width=400><table border=1 cellspacing=0><tr><td bgcolor=blue align=center width=" & ConvertToPix(responseCount) & "><font face='ms sans serif' color=white><b>" & ConvertToPercent(responseCount) & "</td></tr></table></td>"
                 Response.Write "</tr>"
          End If
      Next

      Function ConvertToPix(sz)
            If sz = 0 Then
                   ConvertToPix = 0
            Else
                   ConvertToPix = Cint(400/Total * sz)
            End If
      End Function

      Function ConvertToPercent(sz)
            If sz = 0 Then
                   ConvertToPercent = "0%"
            Else
                   ConvertToPercent = FormatPercent(sz/Total, 2)
            End If
      End Function

%>

</table>


<% If num = "" Then %>
<br><br>
<table border=0 cellspacing=0 cellpadding=0><tr>

  <td colspan=3 align=center><font face="verdana">
   <a href="default.asp?ID=<%=id%>">Add Your Vote</a>
  </td></tr>
</table>

<% End If %>

<br><br>
<table width=100%><tr><td align=right>
<table border=1 cellpadding=5 cellspacing=0 bordercolor=#f5fcdc><tr><td bgcolor=#2f2f4f>
<font face='verdana' size=+1><a href='javascript:history.back()'>Back</a>
</td></tr></table>
</td></tr></table>

</center>
</body>
</html>

上一页  [1] [2] 



打印本文 打印本文  关闭窗口 关闭窗口