5 Replies Latest reply on Jul 22, 2008 12:34 PM by mr. modus

    Creating Questions & Tallying Scores

    newportri Level 1
      Greetings

      I am creating online tests in which the user score needs to be recorded.

      I have them log in and go to the test, which creates a new record in the DB with the date and start time. After submitting the test, the number correct and finish time updates their record based on the session_ID variable.

      The way I have set up the test form is attached. Each question has its own query (X50) and the correct answers are tallied with the action code.

      My issues are:

      1) Can this be accomplished without the necessity of a query for each question?
      2) What's the safest way to keep their ID variable alive - session or application (some may have cookies disabled- they will be taking the test from multiple locations)?
      3) Is there a more efficient way to tally the score?
      3) I am using what they enter in as their employee number for the session_ID- could this be an issue?

      Thanks in advance for any advice.

      rinorman
        • 1. Re: Creating Questions & Tallying Scores
          mr. modus Level 1
          newportri,

          I would say there is probably a much better way to do what you want to do, however before taking the time to write you some code I have a few questions.

          First, do you have all the questions on one page or is it one question per page?
          Second, do you need to tally the scores as you go or can you tally at the end of the test?

          I also noticed you have an extra step in those code:

          <cfif #form.ans_02# eq #ans_correct#>
          <CFSET num_correct = num_correct +1>
          <cfelse>
          <CFSET num_correct = num_correct +0>
          </cfif>

          What's the point of adding zero? Why not just have...
          <cfif #form.ans_02# eq #ans_correct#>
          <CFSET num_correct = num_correct +1>
          </cfif>

          Answer the questions above and I'm sure we can come up with a better way. Off hand I would think you should only run one query to get the answers then loop through the query to tally scores. No sense having a query for each question.
          • 2. Re: Creating Questions &amp; Tallying Scores
            newportri Level 1
            mr. modus

            Thanks for your response.

            All questions are on one continuous page.

            I think I got errors until I added the +0 thing

            The code at the end of the tallying page is:

            <cfoutput>

            <cfquery datasource="some_db" name="correct_answers">
            UPDATE testtaker
            SET num_correct = ('#num_correct#')
            WHERE test_taker_ID = #test_taker_ID#
            </cfquery></cfoutput>

            <cfoutput>

            <cfquery datasource="some_db" name="end_tme">
            UPDATE testtaker
            SET test_taker_tm_end = ('#endtime#')
            WHERE test_taker_ID = #test_taker_ID#
            </cfquery></cfoutput>

            The method of counting correct answers when there is more than one ("check all that apply") through me off as far as looping through questions/answers.

            Thanks again for your help.

            newportri

            • 3. Re: Creating Questions &amp; Tallying Scores
              newportri Level 1
              Sorry- I forgot to add that I am now using the UUID as the session variable, and that lets me use it to identify the record immediately:
              • 4. Re: Creating Questions &amp; Tallying Scores
                newportri Level 1
                Michael:

                While you're in the mood to look into my code- there is the problem of field validation- the code at present fails if the user misses a question, and, using either JS client or CF server validation would require every radio button and /or checkbox to be individually validated- using my method, 50 questions X 4 possible answers = 200 lines of validation code...

                Thanks!
                • 5. Re: Creating Questions &amp; Tallying Scores
                  mr. modus Level 1
                  Newportri,

                  "I think I got errors until I added the +0 thing"
                  - I can't see why this would be, unless by default num_correct is a zero length string rather than 0.

                  "there is the problem of field validation- the code at present fails if the user misses a question"
                  - I suggust using javascript and validating on the client side. I'd just loop over the form elements and make sure each radio set has at least one value checked. This is pretty easy to do and doesn't require many lines of js code.

                  One thing I'll also mention is that it appears you are running a separate query for each value you are updating. This is way more overhead than you need. For instance the following two queries should be written as one. Also note I've removed the <cfoutput> tags since you don't need them inside a CFQUERY tag. It automatically resolves variable values.

                  Also, I notice you are inserting the var "endtime" as a string. I'm assuming this is a date,time or date/time value. I wonder why you wouldn't make the test_taker_tm_end column in your database a smalldatetime or datetime type. That way you can actually query it as a date object rather than having to do string comparisons on it.

                  Why don't you just email me ALL of your code and I'll look at it and see what I can do to streamline/make it work.
                  email me at: mgrant at modus.bz

                  Cheers,