|
<% set conemp = server.createobject("adodb.connection") conemp.open "Driver=SQL Server;Server=sagedbweb;DataBase=Bookexam", "webuser", "webuser" dim strSQL dim recExam dim recAnswer dim strQuestion dim strAnswer dim strQuestion_answer dim strAnswerError dim recError dim blnLastQuestion if Request.QueryString("id") <> "" or Request.Form("actCMD") <> "Submit Answer" then if Request.QueryString("id") <> "" then strSQL = "Select * From Exam where exam_id = " & Request.QueryString("id") else strSQL = "Select * From Exam where exam_id = " & Request.form("examid") end if set recExam = conemp.execute(strSQL) Response.Write "" & recExam("exam_desc") & " " recExam.close set recExam = nothing end if if Request.QueryString("id") <> "" then Call DisplayQuestion(Request.QueryString("questionid"), Request.QueryString("id"), 0) if Request.form("submitquestion") = "Submit Answer" then if Request.Form("rad1") = "" then Response.Write "You must select an answer." Response.End end if strSQL = "Select " strSQL = strSQL & "qa.question_answer_correct_yn " strSQL = strSQL & ",qa.answer_id " strSQL = strSQL & ",q.question_desc " strSQL = strSQL & ",a.answer_desc " strSQL = strSQL & "From " strSQL = strSQL & "Question_answer qa " strSQL = strSQL & "JOIN Question q ON " strSQL = strSQL & "(q.question_id = qa.question_id) " strSQL = strSQL & "JOIN Answer a ON " strSQL = strSQL & "(a.answer_id = qa.answer_id) " strSQL = strSQL & "Where " strSQL = strSQL & "qa.question_id = " & Request.Form("questionid") & " " strSQL = strSQL & "AND qa.answer_id = " & Request.Form("rad1") ' Response.Write strSQL ' Response.end set recAnswer = conemp.execute(strSQL) strSQL = "Select " strSQL = strSQL & "e.exam_id, " strSQL = strSQL & "e.exam_desc, " strSQL = strSQL & "q.question_id, " strSQL = strSQL & "q.question_desc, " strSQL = strSQL & "a.answer_id, " strSQL = strSQL & "a.answer_desc " strSQL = strSQL & "From " strSQL = strSQL & "Exam e " strSQL = strSQL & "JOIN Exam_question eq ON " strSQL = strSQL & "(e.exam_id = eq.exam_id) " strSQL = strSQL & "JOIN Question q ON " strSQL = strSQL & "(q.question_id = eq.question_id) " strSQL = strSQL & "JOIN Question_answer qa ON " strSQL = strSQL & "(q.question_id = qa.question_id) " strSQL = strSQL & "JOIN Answer a ON " strSQL = strSQL & "(a.answer_id = qa.answer_id) " strSQL = strSQL & "Where " strSQL = strSQL & "e.exam_id = " & Request.form("examid") & " " strSQL = strSQL & "Order By " strSQL = strSQL & "eq.exam_question_seq_no, " strSQL = strSQL & "qa.question_answer_seq_no " set recExam = conemp.execute(strSQL) blnLastQuestion = FALSE do until recExam.eof if recExam("question_id") = cint(Request.Form("questionid")) then blnLastQuestion = true if blnLastQuestion = true then if recExam("question_id") <> cint(Request.Form("questionid")) then exit do end if recExam.movenext loop if recAnswer("question_answer_correct_yn") = True then Response.Write "Correct answer! "
if not recExam.eof then
Response.Write "Question: " & recAnswer("question_desc") & " "
%>&questionid=<%=recExam("question_id")%>>Go to the next question.<%
' Call DisplayQuestion(recExam("question_id"), Request.Form("examid"), 0)
else
Response.Write "Thank you for completing our exam!"
end if
else
if Request.Form("errcount") = 2 then
strSQL = "Select "
strSQL = strSQL & "a.answer_desc "
strSQL = strSQL & ",eq.exam_question_error_desc "
strSQL = strSQL & "FROM "
strSQL = strSQL & "Question_answer qa "
strSQL = strSQL & "JOIN Answer a ON "
strSQL = strSQL & "(a.answer_id = qa.answer_id) "
strSQL = strSQL & "JOIN Exam_question eq ON "
strSQL = strSQL & "(qa.question_id = eq.question_id) "
strSQL = strSQL & "Where "
strSQL = strSQL & "qa.question_id = " & Request.Form("questionid") & " "
strSQL = strSQL & "AND eq.exam_id = " & Request.Form("examid") & " "
strSQL = strSQL & "AND qa.question_answer_correct_yn = 1 "
' Response.Write strSQL
' Response.End
set recError = conemp.execute(strSQL)
Response.Write "Correct answer is: " & recError("answer_desc") & " Go to the next question" else Response.Write "Thank you for taking our exam!" end if else if Request.Form("errcount") = 1 then Response.Write "Incorrect, one more try please." else Response.Write "Incorrect, please try again." end if Call DisplayQuestion( Request.Form("questionid"), Request.Form("examid"), Request.Form("errcount") + 1) end if end if end if Sub DisplayQuestion(qid, exid, intErrorCount) strSQL = "Select " strSQL = strSQL & "e.exam_id " strSQL = strSQL & ",e.exam_desc " strSQL = strSQL & ",q.question_id " strSQL = strSQL & ",q.question_desc " strSQL = strSQL & ",a.answer_id " strSQL = strSQL & ",a.answer_desc " strSQL = strSQL & "From " strSQL = strSQL & "Exam e " strSQL = strSQL & "JOIN Exam_question eq ON " strSQL = strSQL & "(e.exam_id = eq.exam_id) " strSQL = strSQL & "JOIN Question q ON " strSQL = strSQL & "(q.question_id = eq.question_id) " strSQL = strSQL & "JOIN Question_answer qa ON " strSQL = strSQL & "(q.question_id = qa.question_id) " strSQL = strSQL & "JOIN Answer a ON " strSQL = strSQL & "(a.answer_id = qa.answer_id) " strSQL = strSQL & "Where " strSQL = strSQL & "e.exam_id = " & exid & " " strSQL = strSQL & "AND eq.question_id = " & qid & " " strSQL = strSQL & "Order By " strSQL = strSQL & "eq.exam_question_seq_no, " strSQL = strSQL & "qa.question_answer_seq_no " set recExam = conemp.execute(strSQL) %> <% End Sub %>Chap 1 Chap 2 Chap 3 Chap 4 Chap 5 Chap 6 Chap 7 Chap 8 |