分享

asp做问卷调查 投票

 haiaiying 2011-06-29

新建一个文件夹将下列文件按照提示放到文件夹中

在文件夹中建一个名为 img 的文件夹

图:  asp做问卷调查 <wbr>投票

将此图片存入img文件夹 名为 bar.gif

首先是数据库链接文件coon.asp:

<%
'连接数据库开始
dim conn,rs,sql
'on error resume next
dbpath=server.mappath("data.mdb")
set conn=server.createobject("adodb.connection")
conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0;data source="&dbpath
'创建记录对象
set rs=server.createobject("adodb.recordset")
%>

制作一个用来投票的页面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>
</head>
<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>
      <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> </p>
</body>
</html>

 

updata页面将数据处理后重定向到show.asp来显示投票结果

show.asp:

<!--#include file="conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www./1999/xhtml">
<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>
<body>
<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
  rs.close
  
  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>

 

<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
  rs.close
  
  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>
</div>
</body>
</html>

 

建立Access数据库

首先建一个名为data的数据库

在data中建两个表分别名为:askItem   和   askTitle

askTitle中   id 自动编号  askTitle 文本

askItem中    id 自动编号  aID 数字  askItem 文本  subNum 数字

asp做问卷调查 <wbr>投票

 

 

asp做问卷调查 <wbr>投票

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多