asp做问卷调查
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
a s p做问卷调查投票
新建一个文件夹将下列文件按照提示放到文件夹中
在文件夹中建一个名为 img 的文件夹
图:
将此图片存入img文件夹名为 bar.gif
首先是数据库链接文件coon.asp:
制作一个用来投票的页面add.asp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>问卷调查</title>
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body,td,th {
font-family: 宋体;
font-size: 14px;
}
-->
</style>
<body>
<form name="form1" method="post" action="updata.asp">
<center>
<div class="bigbox" style="border:#3399FF 3px double; width:500px; padding:5px"> <table width="554" border="0">
<tr>
<td>1.请问您公司的性质是什么?</td>
</tr>
<tr>
<td>
<input type="checkbox" name="ask1" value="A 国家机关">
A 国家机关</td>
</tr>
<tr>
<td><input type="checkbox" name="ask1" value="B 全民企业单位">
B 全民企业单位</td>
</tr>
<tr>
<td><input type="checkbox" name="ask1" value="C 私营企业">
C 私营企业</td>
</tr>
<td><input type="checkbox" name="ask1" value="D 个体商户">
D 个体商户</td>
</tr>
<tr>
<td><input type="checkbox" name="ask1" value="E 外资企业">
E 外资企业</td>
</tr>
</table>
</div>
<div class="bigbox" style="border:#3399FF 3px double; width:500px; padding:5px"> <table width="554" border="0">
<tr>
<td>2.请问您公司的人数是多少?</td>
</tr>
<tr>
<td>
<input type="checkbox" name="ask2" value="A 0-10">
A 0-10</td>
</tr>
<tr>
<td><input type="checkbox" name="ask2" value="B 10-30">
B 10-30</td>
</tr>
<tr>
<td><input type="checkbox" name="ask2" value="C 30-50">
C 30-50</td>
</tr>
<tr>
<td><input type="checkbox" name="ask2" value="D 50-100">
D 50-100</td>
</tr>
<tr>
<td><input type="checkbox" name="ask2" value="E 100以上">
E 100以上</td>
</tr>
</table>
</div>
<center>
<input name="Submit" type="submit" class="button" value="投票"> <a href="show.asp">查看结果</a>
</center>
</form>
</body>
</html>
单击投票按钮 FORM表单将数据提交给updata.asp页面进行处理
updata.asp:
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>投票成功</title>
</head>
<body>
<p>
<%
str1 = Request.Form("ask1")
str2 = Request.Form("ask2")
if str1="" or str2="" then
response.write "<script lanaguage=javascript>alert('每题至少选一项,请填写完整');history.back();</script>"
response.End()
end if
set rs=server.createobject("adodb.recordset")
sql=" select * from askItem where aId=1"
rs.open sql,conn,1,1
do while not rs.eof
if instr(str1,rs("askItem"))>0 then
sql = "update askItem set subNum=subNum+1 where id="&rs("id") conn.execute(sql)
end if
rs.movenext
loop
rs.close
sql=" select * from askItem where aId=2"
rs.open sql,conn,1,1
do while not rs.eof
if instr(str2,rs("askItem"))>0 then
sql = "update askItem set subNum=subNum+1 where id="&rs("id") conn.execute(sql)
end if
rs.movenext
loop
rs.close
Response.Redirect("show.asp")
%>
<p> </p>
</body>
</html>
updata页面将数据处理后重定向到show.asp来显示投票结果
show.asp:
<!--#include file="conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>投票结果</title>
<style type="text/css">
<!--
.STYLE1 {
font-family: "黑体";
font-size: 24px;
color: #FF0000;
}
-->
</style>
</head>
<div class="bigbox" style="border:#3399FF 3px double; width:560px; padding:5px">
<table width="100%" border="1" cellspacing="0" cellpadding="3"
bordercolordark="#FFFFFF" bordercolorlight="#000000">
<tr>
<td colspan="4" align="center">1.请问您公司的性质是什么?</td>
</tr>
<tr>
<td width="42%" align="center">选项</td>
<td width="34%" align="center">柱状图</td>
<td width="10%" align="center">票数</td>
<td width="14%" align="center">%</td>
</tr>
<%
set rs=server.createobject("adodb.recordset")
sql=" select * from askItem where aId=1"
rs.open sql,conn,1,1
Dim topnum
topnum=0
do while not rs.eof
topnum = topnum+rs("subNum")
rs.movenext
loop
sql=" select * from askItem where aId=1"
rs.open sql,conn,1,1
do while not rs.eof
%>
<tr>
<td><%=rs("askItem")%></td>
<td><img src="img/bar.gif" width="<%If topnum=0 Then Response.Write("1") Else Response.Write(int(rs("subNum")/topnum*100)) end if%>" height="10"></td>
<td align="center"><%=rs("subnum")%></td>
<td align="center"> <%If topNum=0 Then Response.Write("-") Else
Response.Write(int(rs("subNum")/topNum*1000)/10) end if%>
%</td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</table>
<div class="bigbox" style="border:#3399FF 3px double; width:560px; padding:5px">
<table width="100%" border="1" cellspacing="0" cellpadding="3"
bordercolordark="#FFFFFF" bordercolorlight="#000000">
<tr>
<td colspan="4" align="center">2.请问您公司的人数是多少?</td>
</tr>
<tr>
<td width="42%" align="center">选项</td>
<td width="34%" align="center">柱状图</td>
<td width="10%" align="center">票数</td>
<td width="14%" align="center">%</td>
</tr>
<%
set rs=server.createobject("adodb.recordset")
sql=" select * from askItem where aId=2"
rs.open sql,conn,1,1
dim topnum2
topnum2=0
do while not rs.eof
topnum2 = topnum2+rs("subNum")
rs.movenext
loop
sql=" select * from askItem where aId=2"
rs.open sql,conn,1,1
do while not rs.eof
%>
<tr>
<td><%=rs("askItem")%></td>
<td><img src="img/bar.gif" width="<%If topnum2=0 Then Response.Write("1") Else Response.Write(int(rs("subNum")/topnum2*100)) end if%>" height="10"></td>
<td align="center"><%=rs("subnum")%></td>
<td align="center"> <%If topNum2=0 Then Response.Write("-") Else
Response.Write(int(rs("subNum")/topNum2*1000)/10) end if%>
%</td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</table>
</body>
</html>
建立Access数据库
首先建一个名为data的数据库
在data中建两个表分别名为:askItem 和 askTitle
askTitle中 id 自动编号 askTitle文本
askItem中 id 自动编号 aID 数字 askItem 文本 subNum 数字。