| 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参数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="#0 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页 |