欢迎光临
我们一直在努力

用ASP学做一个在线调查(4)-ASP教程,ASP应用

建站超值云服务器,限时71元/月

八、列出所有调查的状态

  现在我们来完成survey.asp,它的主要任务是列出所有的调查状态,包括:

  1、调查的问题,链接到投票表单页面(直接写在本页中);

  2、调查的起启时间;

  3、调查的结束时间;

  4、调查的进行状态:未开始、进行中、已结束;

  5、调查的投票数;

  6、调查的类型,单选还是多选;

  7、另外给出一个链接查看投票结果;

  根据这些要求,查询相应的表就可以了,有些语句,比如得到投票总数,sql语句其实在上面的survey_vote.asp中已经写过了。

  列出所有调查的状态 survey.asp

<!–#include file=”inc.asp” –>
<html>
<head>
<title>在线调查列表</title>
<link rel=”stylesheet” href=”main.css” type=”text/css”>
</head>
<body>
<%
id=request.querystring(“id”) 获取参数
if id<>”” then 如果有参数,则显示这个调查表单
response.write “<script language=javascript src=surveycode.asp?id=”&id&”></script>”
else 否则调用子程序显示状态
disstat()
end if

—–显示状态子程序—-
sub disstat()
opendb my 连接数据库
opentable my,”survey”,rs 直接打开表
下面用表格显示每个记录
先显示表头
%>
<table width=”760″ border=”1″ cellspacing=”0″ cellpadding=”2″
align=”center” bordercolorligh=”#000000″ bordercolordark=”#ffffff”>
<tr>
<td colspan=”8″ align=”center”><b>在线调查列表</b></td>
</tr>
<tr >
<td width=”50″ align=”center” height=”20″>编号</td>
<td width=”200″ align=”center” height=”20″>调查问题</td>
<td width=”50″ align=”center” height=”20″>类型</td>
<td width=”140″ align=”center” height=”20″>起启时间</td>
<td width=”140″ align=”center” height=”20″>结束时间</td>
<td width=”50″ align=”center” height=”20″>状态</td>
<td width=”80″ align=”center” height=”20″>已投票数</td>
<td width=”50″ align=”center” height=”20″>查看</td>
</tr>
<%
下面输出每个记录
do while not rs.eof
先读出每个字段
id=rs(“survey_id”)
question=rs(“survey_question”)
读出类型
if rs(“survey_type”) then
stype=”多选”
else
stype=”单选”
end if
stime=rs(“survey_stime”)
etime=rs(“survey_etime”)
判断状态
if now()<stime then
stat=”未开始”
else
if now<etime then
stat=”进行中”
else
stat=”已结束”
end if
end if

定义sql语句,得到答案的数量总和
sql=”select sum(vote_count) as total from survey_vote where vote_id=”& id
searchtable my,sql,tmprs 查询
total=tmprs(“total”)
closetable tmprs 关闭表
下面输出一条记录
%>
<tr >
<td align=”center” height=”20″><%=id%></td>
<td height=”20″>
<a href=”survey.asp?id=<%=id%>”><%=question%></a>
</td>
<td align=”center” height=”20″><%=stype%></td>
<td align=”center” height=”20″><%=stime%></td>
<td align=”center” height=”20″><%=etime%></td>
<td align=”center” height=”20″><%=stat%></td>
<td align=”center” height=”20″><%=total%></td>
<td align=”center” height=”20″>
<a href=”survey_vote.asp?id=<%=id%>” target=”_blank”>查看</a>
</td>
</tr>
<%
rs.movenext 移动到下一条,循环
loop
%>
</table>
<%
closetable rs 关闭表
closedb my 关闭数据库
end sub
———————-
%>
</body>
</html>

  九、后台管理

  在后台管理页面survey_manage.asp中,前面我们已经列出来它所要实现的管理功能。管理的流程是先显示出所有调查,对于还没有开始的调查,可以进行修改、删除;对于已经结束的调查,可以删除,不能修改;对于正在进行的调查,只能修改它的结束时间。用一个参数action来表示动作,含义如下:

  1、无参数。表示第一次进入,显示登录表单

  2、login 表示执行登录

  3、logout 表示执行退出登录

  4、showaddquestion 表示显示增加一个调查

  5、showsurvey 表示显示一个调查

  6、doaddsurvey 表示执行增加一个调查

  7、doaddanswer 表示执行增加一个答案

  8、dodelsurvey 表示删除一个调查

  9、dodelanswer 表示删除一个答案

  10、domodify 表示修改一个调查及答案

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用ASP学做一个在线调查(4)-ASP教程,ASP应用
分享到: 更多 (0)