扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:pppasp 来源:论坛 2007年10月17日
关键字:
<!--#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 ''查询答案的SQL searchtable 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.movenext next ''下面几句输出一个隐藏的参数,传递问题编号(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 if end if end if closetable rs closedb my end if %> |
<!--#include file="inc.asp" --> <html> <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 width="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> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者