• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Creating Questions & Tallying Scores

New Here ,
Jul 16, 2008 Jul 16, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

464

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

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:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

LATEST
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,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation