<% dim survey_id dim results_id dim user_id dim question_id dim answer_id dim survey dim list_surveyresults_sql dim answer_total dim question dim answer dim answer_count dim percent_bar dim results_chart_sql sub request_list_surveyresults ''' request form inputs from this form survey_id = request("survey_id") results_id = request("results_id") user_id = request("user_id") question_id = request("question_id") answer_id = request("answer_id") survey = request("survey") end sub sub request_results_chart ''' request form inputs from this form question_id = request("question_id") survey_id = request("survey_id") answer_total = request("answer_total") answer_id = request("answer_id") answer_id = request("answer_id") question = request("question") answer = request("answer") answer_count = request("answer_count") percent_bar = request("percent_bar") end sub sub validate_list_surveyresults ''' request and validate data entered from this form survey_id = trim(request("survey_id")) results_id = trim(request("results_id")) user_id = trim(request("user_id")) question_id = trim(request("question_id")) answer_id = trim(request("answer_id")) survey = trim(request("survey")) end sub sub validate_results_chart ''' request and validate data entered from this form question_id = trim(request("question_id")) survey_id = trim(request("survey_id")) answer_total = trim(request("answer_total")) answer_id = trim(request("answer_id")) answer_id = trim(request("answer_id")) question = trim(request("question")) answer = trim(request("answer")) answer_count = trim(request("answer_count")) percent_bar = trim(request("percent_bar")) end sub sub db_select_list_SurveyResults list_SurveyResults_sql = "SELECT " & _ "SurveyAnswers.answer, " & _ "Surveys.survey_id, " & _ "Surveys.survey, " & _ "SurveyQuestions.question, " & _ "SurveyResults.results_id, " & _ "SurveyResults.user_id, " & _ "SurveyResults.question_id, " & _ "SurveyResults.answer_id, " & _ "SurveyResults.answer_value, " & _ "SurveyResults.dt_inserted, " & _ "SurveyResults.user_ip FROM (((SurveyResults INNER JOIN SurveyQuestions ON SurveyResults.question_id = SurveyQuestions.question_id)" & _ " INNER JOIN SurveyAnswers ON SurveyAnswers.answer_id = SurveyResults.answer_id)" & _ " INNER JOIN Surveys ON Surveys.survey_id = SurveyQuestions.survey_id) " & _ " WHERE SurveyQuestions.survey_id = " & survey_id & "" & _ " ORDER BY question" & _ "" if request("sortby") <> "" AND inStr(lcase(list_SurveyResults_sql),"order by") = 0 then list_SurveyResults_sql = list_SurveyResults_sql + " ORDER BY " & request("sortby") end sub sub db_delete_list_SurveyResults sql = "DELETE FROM SurveyQuestionsSurveyResults" & _ " WHERE " & _ "survey_id = " & to_sql(survey_id,"number") & " AND " & _ "results_id = " & to_sql(results_id,"number") & " AND " & _ "question_id = " & to_sql(question_id,"number") & "" 'response.write sql on error resume next cn.Execute(sql) if err.number <> 0 then b_error = true end if on error goto 0 end sub sub db_select_results_chart results_chart_sql = "SELECT min(question) as question, min(answer) as answer, count(SurveyResults.answer_id) AS answer_count FROM ((SurveyResults LEFT JOIN SurveyQuestions ON SurveyQuestions.question_id = SurveyResults.question_id) RIGHT JOIN SurveyAnswers ON SurveyResults.answer_id = SurveyAnswers.answer_id) WHERE SurveyQuestions.survey_id = " & survey_id & " GROUP BY Surveyanswers.answer_id" if request("sortby") <> "" AND inStr(lcase(results_chart_sql),"order by") = 0 then results_chart_sql = results_chart_sql + " ORDER BY " & request("sortby") end sub sub db_delete_results_chart sql = "DELETE FROM " & _ "" 'response.write sql on error resume next cn.Execute(sql) if err.number <> 0 then b_error = true end if on error goto 0 end sub do_search = request("do_search") ''' request form keys and inputs survey_id = request("survey_id") results_id = request("results_id") question_id = request("question_id") ':: handle the default case(s) for each form (separate from action= parameter) if survey_id <> "" then db_select_list_surveyresults db_select_results_chart else error_list.add "nosurvey_id", "Please specify the survey_id to view results." end if %> <% display_errs display_msg %> <% page_no = request("page_no") if page_no = "" then page_no = 1 if list_SurveyResults_sql <> "" then cmd.CommandText = list_SurveyResults_sql rs.Filter = "" if survey_id <> "" then rs.Filter = "survey_id = " & to_sql(survey_id,"number") rs.CursorLocation = 3 rs.CacheSize = 5 rs.Open cmd if not rs.EOF then rs.MoveFirst max_count = cInt(rs.PageCount) num_recs = rs.RecordCount rs.AbsolutePage = page_no results = true else results = false rs.Close end if else results = false end if rec_count = 0 %>
Surveys › Survey Results
<% if results = true then %> <% do while not rs.EOF ':: read db record on error resume next survey_id = rs("survey_id") results_id = rs("results_id") user_id = rs("user_id") question_id = rs("question_id") answer_id = rs("answer_id") survey = rs("survey") on error goto 0 %> <% if lastgroup <> question OR (isnull(lastgroup) AND question <> "") then %><% end if %> <% lastgroup = question rs.MoveNext rec_count = rec_count + 1 loop rs.Close %>
<% =question %>
<% else %> no matches were found. <% end if %> <% answer_total = rec_count %> <% =answer_total %> responses. <% page_no = request("page_no") if page_no = "" then page_no = 1 if results_chart_sql <> "" then cmd.CommandText = results_chart_sql rs.Filter = "" rs.CursorLocation = 3 rs.CacheSize = 5 rs.Open cmd if not rs.EOF then rs.MoveFirst max_count = cInt(rs.PageCount) num_recs = rs.RecordCount rs.AbsolutePage = page_no results = true else results = false rs.Close end if else results = false end if rec_count = 0 %> <% if results = true then %> <% do while not rs.EOF ':: read db record on error resume next question_id = rs("question_id") survey_id = rs("survey_id") answer_total = rs("answer_total") answer_id = rs("answer_id") answer_id = rs("answer_id") question = rs("question") answer = rs("answer") answer_count = rs("answer_count") percent_bar = rs("percent_bar") on error goto 0 %> <% rs.MoveNext rec_count = rec_count + 1 loop rs.Close %>
?<% =request_string %>page_no=<% =page_no %>&sortby=question" class=fieldFont title="">question ?<% =request_string %>page_no=<% =page_no %>&sortby=answer" class=fieldFont title="">answer responses response rate
<% if question <> lastquestion then set rs2 = Server.CreateObject("ADODB.Recordset") cmd.CommandText = "SELECT * FROM SurveyResults WHERE question_id = " & question_id rs2.CursorLocation = 3 rs2.Open cmd answer_total = rs2.RecordCount rs2.Close set rs2 = NOTHING %><% =question %><% end if lastquestion = question %> <% =answer %> <% =answer_count %> out of <% =answer_total %>
<% =formatpercent(answer_count/answer_total,2) %>
<% =percent_bar %>
<% else %> <% end if %> <% ':: assure that any db resources are freed on error resume next rs.Close set rs = NOTHING cn.Close set cn = NOTHING user_cn.Close set user_cn = NOTHING on error goto 0 %>