vote.asp
来自「ASP+SQL Server动态网站开发从基础到实践教程」· ASP 代码 · 共 146 行
ASP
146 行
<%
on error resume next
'获取用户提交的数据
o = request.querystring("sql") '如果是通过get方法提交,即单击了图13-1上面的一个vote链接
p = request.form("sql") '如果是通过post方法提交,即单击了图13-1下面的一个vote链接
'将提交的数据赋值给变量i
if o = "" then
i = p
else
i = o
end if
'打开数据库链接
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;data source=(local);initial catalog=vote;user id=sa;password=;"
'创建查询语句
sql = "SELECT * FROM title, vote where title.id = vote.id and title.title = '" & i & "'"
set rs = server.CreateObject ("ADODB.Recordset")
rs.Open sql, conn, 3, 3
%>
<%
'count all voters
all = 0
rs.movefirst
do while not rs.eof
'for z = 1 to rs.recordcount
all = all + rs.fields("novote")
rs.movenext
loop
if rs.eof then
rs.movelast
end if
'next
%>
<html>
<head>
<title>Poll - results</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="stili.css" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<center>
<table width="400" border="1" cellspacing="0" cellpadding="4" class="nortxtv10"
bordercolor="#CCCCCC" bordercolorlight="#000000" bordercolordark="#000000" style="border-collapse: collapse">
<tr>
<td colspan="2" nowrap align="center" bgcolor="lightblue"><b><%=rs.fields("title")%></b> </td>
</tr>
<%
'显示投票结果..
rs.movefirst
do while not rs.eof
'for a = 1 to rs.recordcount
%>
<%
Dim b, c
b = CInt(rs.fields("novote"))
'如果没有获得投票.
if b = "0" then
%>
<tr bgcolor="#333333">
<td width="300" nowrap align="left" valign="middle" bgcolor="#336699">
<font color="#FFFFFF"><%=rs.fields("answer")%></font></td>
<td width="100" nowrap align="right" valign="middle" bgcolor="#336699">
<font color="#FFFFFF"><%= "0% (0)" %></font></td>
</tr>
<tr>
<td colspan="2" nowrap align="left" valign="middle">没有投票!</td>
</tr>
<%
else
'则计算支持率,
c = Cint(100 / all * b)
%>
<tr bgcolor="#333333">
<td width="300" nowrap align="left" valign="middle" bgcolor="#336699">
<font color="#FFFFFF"><%=rs.fields("answer")%></font></td>
<td width="100" nowrap align="right" valign="middle" bgcolor="#336699">
<font color="#FFFFFF"><%= c & "%" & " (" & rs.Fields("novote") & ")" %></font></td>
</tr>
<tr>
<td colspan="2" nowrap align="left" valign="middle">
<img src="images/bar<%=rs.fields("pic")%>.gif" height="10" width="<%= 4*c %>"></td>
</tr>
<%
end if
%>
<%
rs.movenext
loop
if rs.eof then
rs.movelast
end if
'next
%>
<tr>
<td colspan="2" nowrap align="center" bgcolor="lightblue">总投票数: <font color="red"><b><%=all%></b></font></td>
</tr>
</table>
</center>
</div>
<p align="center"><a href="javascript:history.go(-1)" class="nortxtv10">返回</a></p>
</body>
</html>
<%
'关闭数据库链接
rs.Close
set rs = nothing
conn.Close
set conn = nothing
%>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?