ml>
<head>
<title>调查统计结果</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<%
上一句先加入包含文件,引用函数。
id=request.querystring("id") 获取querystring参数id
opendb my 连接数据库
if id="" then 如果没有,则不是直接看结果
id=request.form("id") 获取form参数id
if id<>"" then 如果有值,则是要先统计
surveycount() 调用统计子程式
end if
end if
if id<>"" then
disp_survey() 不管是哪种,最后都显示结果
end if
closedb my 关闭数据库
-----统计子程式-----
sub surveycount()
if session("survey_ok")="" then 如果还没投票
no=request.form("res") 得到答案的编号
if no<>"" then
定义sql语句,让提交的答案数量+1
sql="update survey_vote set vote_count=vote_count+1 where vote_no= in (" &; no &;")"
my.execute sql
end if
session("survey_ok")="ok"
end if
end sub
------------------
---显示结果子程式---
sub disp_survey()
定义
sql语句,得到调查的问题
sql="select survey_question from survey where survey_id=" &; id
searchtable my,sql,rs 执行查询
question=rs("survey_question") 把问题存到question中
closetable rs 关闭表
定义sql语句,得到答案的数量总和
sql="select sum(vote_count) as total from survey_vote where vote_id="&; id
searchtable my,sql,rs
total=rs("total")
closetable rs 关闭表
定义sql语句,得到所有的答案文本部份及投票数
sql="select vote_answer,vote_count from survey_vote where vote_id=" &; id
searchtable my,sql,rs 执行查询
下面用表格来输出统计表
%>
<table width="500" border="1" align="center" cellpadding="2" cellspacing="0"
bordercolorligh="#000000" bordercolordark="#ffffff">
<tr>
<td colspan="4" align="center"><b>调查统计结果</b></td>
</tr>
<tr>
<td colspan="4"><b>调查问题:<%=question%></b></td>
</tr>
<tr >
<td width="150" align="center" height="20">答案</td>
<td width="150" align="center" height="20">投票率</td>
<td w
idth="100" align="center" height="20">比例</td>
<td width="100" align="center" height="20">票数</td>
</tr>
<%do while not rs.eof
if total=0 then
percent=0 如果没人投票,则百分比为0
else
percent=int(rs("vote_count")/total*10000)/100 计算百分比
end if
%>
<tr>
<td width="150" align="center"><%=rs("vote_answer")%></td>
<td width="150" align="left">
<table border="0" width="<%=percent%>" bgcolor="#cccc00" height="10">
<tr>
<td></td>
</tr>
</table>
</td>
<td width="100" align="center"><%=percent%>%</td>
<td width="100" align="center"><%=rs("vote_count")%></td>
</tr>
<%
rs.movenext
loop
%>
<tr>
<td colspan="4"> 至 <%=now()%> 止,共有 <%=total%> 张投票
<a href="javascript:window.close()">关闭窗口</a>
</td>
</tr>
</table>
<%
closetable rs 关闭表
end sub
------------------
%>
</body>
</html>
在显示投票过程中,我们用session变量survey_ok来表示是否已投过票。另外,这显示统计中,引用css文件来控制表格的样式,你们能根据自己的需求自己加入。