: frankey
Poll #797763 frankey
Open to: All, detailed results viewable to: All, participants: 1
Poll #797763 frankey
Open to: All, detailed results viewable to: All, participants: 1
my homepage
![]() | You are viewing Log in Create a LiveJournal Account Learn more | Explore LJ: Life Entertainment Music Culture News & Politics Technology |
frankey521's JournalRecent Entries | ||
|
|
You are viewing the most recent 7 entries.
17th August 2006
: frankey
Poll #797763 frankey Open to: All, detailed results viewable to: All, participants: 1 my homepage 11th August 2006
: 补充
<%''''获取参数。action表示动作,分别对应上面的功能。''''根据动作 [Error: Irreparable invalid markup ('<now()>') in entry. Owner must fix manually. Raw contents below.]
<%''''获取参数。action表示动作,分别对应上面的功能。''''根据动作来转向相应的子程序''''登录子程序''''退出登录子程序''''执行增加调查问题子程序''''执行增加调查答案子程序''''执行修改调查子程序 问题和答案一起修改''''执行删除调查问题子程序''''执行删除调查答案子程序<html><%''''判断是否登录,没有则显示登录表单''''根据动作显示相应表单''''显示所有调查子程序''''显示单个调查子程序。问题和答案一起显示''''显示增加调查子程序。''''显示登录表单%></html> 六、代码编写 做好了流程设计后,写代码就比较有条理了。让我们从简单的开始。在编写代码之前,我们要先在数据库里输入一些记录,以便做测试。先加入一条调查问题,和几个调查答案,并手工输入一些统计信息。 我们先来写显示调查表单的surveycode.asp 这个文件要在其它页面中被调用,所以我们写成JS和VBS混用的方式。调用的时候可以把它放在某个表格中,用下面的语句:<SCRIPT Language="JavaScript" SRC="surveycode.asp?id=1"></SCRIPT> 按照上面的流程,在显示表单前,先要判断一下调查是否存在,是否在进行中。另外,在表单中要提交一个隐藏的参数,来表示调查的问题编号(id),答案提交的时候,提交的是答案的编号vote_no 文件名 surveycode.asp<!--#include file="inc.asp" --><%id=request.querystring("id")if id<>"" then ''''如果有参数opendb my ''''联接数据库sql="select * from survey where survey_id="& id ''''查询语句searchtable my,sql,rs ''''查询数据库if not rs.eof then ''''如果有这个调查记录question=rs("survey_question") ''''读出问题surveytype=rs("survey_type") ''''读出答案类型stime=rs("survey_stime") ''''读出开始时间etime=rs("survey_etime") ''''读出结束时间closetable rs ''''关闭表if stime<now() and etime>now() then ''''如果调查正在进行中''''下面输出调查表单''''先输出表单和问题,表单提交到survey_vote.asp%>document.write("<form action=''''survey_vote.asp'''' target=''''_blank'''' method=''''post''''>");document.write("<table border=''''1'''' cellpadding=''''2'''' cellspacing=0'''' bordercolorligh=''''#000000''''");document.write(" bordercolordark=''''#ffffff'''' width=''''100%'''' align=''''center''''><tbody>");document.write("<tr><td colspan=''''2'''' align=''''center''''><b><%=server.htmlencode(question)%></b></td></tr>");<%sql="select vote_no,vote_answer from survey_vote where vote_id="&id ''''查询答案的SQLsearchtable my,sql,rs ''''执行查询if not rs.eof then ''''如果有答案,就输出for i=1 to rs.recordcount%> document.write("<tr><td align=''''right''''><input name=''''res'''' type=''''");<%if surveytype then ''''判断类型,显示单选或者多选%>document.write("checkbox");<%else%> document.write("radio");<%end if ''''下面这句输出答案的文字和提交的值(vote_no)%>document.write("'''' value=<%=rs("vote_no")%>></td><td><%=rs("vote_answer")%></td></tr>");<%rs.movenextnext''''下面几句输出一个隐藏的参数,传递问题编号(id)''''并用一个JS函数来定义点击查看后的链接%>document.write("<tr><td colspan=''''2'''' align=''''center''''><input type=''''hidden'''' name=''''id'''' value=''''<%=id%>''''>");document.write("<input type=''''submit'''' class=button value=''''投票''''> ");document.write("<input type=button class=button value=''''查看'''' onclick=''''jump(<%=id%>)''''>");document.write("</td></tr></tbody></table></form>");function jump(id){window.open("survey_vote.asp?id="+id,"survey")}<%end ifend ifend ifclosetable rsclosedb myend if%> 在surveycode.asp完成后,我们实现上已经确定了以下几点: 1、在survey_vote.asp中,如果querystring参数id有值,则是查看结果; 2、在survey_vote.asp中,如果form参数id有值,则要先进行统计; 3、在survey_vote.asp中,提交来的form参数res是答案的编号vote_no; 七、统计结果 首先我们来完成与surveycode.asp最密切相关的显示统计结果survey_vote.asp文件。在上一篇的结尾,我们已经说明了在surveycode.asp中确定的一些参数。 统计结果 survey_vote.asp<!--#include file="inc.asp" --><html><head><title>调查统计结果</title><link rel="stylesheet" href="main.css" type="text/css"></head><body><%''''上一句先加入包含文件,引用函数。id=request.querystring("id") ''''获取querystring参数idopendb my ''''连接数据库if id="" then ''''如果没有,则不是直接看结果id=request.form("id") ''''获取form参数idif id<>"" then ''''如果有值,则是要先统计surveycount() ''''调用统计子程序end ifend ifif id<>"" thendisp_survey() ''''不管是哪种,最后都显示结果end ifclosedb my ''''关闭数据库''''-----统计子程序-----sub surveycount()if session("survey_ok")="" then ''''如果还没投票no=request.form("res") ''''得到答案的编号if no<>"" then''''定义SQL语句,让提交的答案数量+1sql="update survey_vote set vote_count=vote_count+1 where vote_no= in (" & no &")"my.execute sqlend ifsession("survey_ok")="ok"end ifend sub''''------------------''''---显示结果子程序---sub disp_survey()''''定义SQL语句,得到调查的问题sql="select survey_question from survey where survey_id=" & idsearchtable my,sql,rs ''''执行查询question=rs("survey_question") ''''把问题存到question中closetable rs ''''关闭表''''定义SQL语句,得到答案的数量总和sql="select sum(vote_count) as total from survey_vote where vote_id="& idsearchtable my,sql,rstotal=rs("total")closetable rs ''''关闭表''''定义SQL语句,得到所有的答案文本部份及投票数sql="select vote_answer,vote_count from survey_vote where vote_id=" & idsearchtable 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 width="100" align="center" height="20">比例</td><td width="100" align="center" height="20">票数</td></tr><%do while not rs.eofif total=0 thenpercent=0 ''''如果没人投票,则百分比为0elsepercent=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.movenextloop%><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文件来控制表格的样式,你们可以根据自己的要求自己加入。 八、列出所有调查的状态 现在我们来完成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") thenstype="多选"elsestype="单选"end ifstime=rs("survey_stime")etime=rs("survey_etime")''''判断状态if now()<stime thenstat="未开始"elseif now<etime thenstat="进行中"elsestat="已结束"end ifend if''''定义SQL语句,得到答案的数量总和sql="select sum(vote_count) as total from survey_vote where vote_id="& idsearchtable 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 表示修改一个调查及答案
: 在线调查系统
asp制作在线调查系统关于在线调查大家一定不会陌生吧,给出一个问题和数个答案,让 一、功能设计 这么简单的系统也要做功能设计?有的人也许会觉得奇怪,不过话说回来不管怎么样的系统,先 10th August 2006
: 学习SPSS的几点笔记
utilities-------variable...查询数据库变量 多项选择题分析使用 analyze----multiple----define multiple response sets tables----multiple 将字符型变量变成数值型 transform -----automatic recode 或者 rank cases Current Mood: accomplished
: 标签不知道如何 使用
谁知道可以告诉我 谢谢! who can tell me how to use the tags ?
: test
test Current Mood:
: 验证成功信息
成功 Thanks! The email address for frankey521 has now been verified(核实). From here, you may be interested (有益的,得到帮助的) in doing the following things: Log In -- So you don't have to enter your username and password everywhere. Edit Information (资料)-- Fill out your user profile and set various settings. Customize Journal -- Customize the look of your journal Update Journal (更新) -- Write in your journal. |
|