ASP based Online Quiz
I am building an ASP based online quiz which will have the following format.
'--------------------------------------
Example Situation
'--------------------------------------
Question 1
Question 2
Question 3
Question 4
Question 5
'--------------------------------------
The same format will be used for 5 examples on the same page. Each example will have the same 5 questions.
For the form part to be simple I created the form with 1 situation and by pulling it all from a database it's looping through that same form 5 times. The problem is the name of the fields are Question 1, 2, 3, 4, 5 for each form. Request.Form("Question1") returns 1, 1, 2, 3, 2 if it's pulling the data from this form.
What is the easiest way to send this data and be able to score it and save all results to a database?
Mark Hensler posted this at 16:04 — 24th October 2001.
He has: 4,048 posts
Joined: Aug 2000
I usually create dynamic form names for the fields. Usually Example number and Questions number. Then loop through the examples and 1-5, and grab your vars/values and do whatever with them
For Example=1 To 5
For Question=1 To 5
Answer = Request.Form(Example & "_" & Question)
' do something with it
Next
Next
Mark Hensler
If there is no answer on Google, then there is no question.
Peter J. Boettcher posted this at 16:11 — 24th October 2001.
They have: 812 posts
Joined: Feb 2000
You have to be a little careful when you're pulling generic form values like that, the order you get the values in doesn't always match the order they are in the page (actually it never matches). So for each form I would add a unique integer via a counter, so in the first form the field would be "1Question1", in the second it would be "2Question1", etc. As for the database setup, I would do the following:
QuizMain table
--------------
QuizID
QuizTitle
QuizQuestion table
------------------
QuizQuestionID
QuizID --> link to QuizMain
QuizQuestion
QuizAnswer table
----------------
QuizAnswerID
QuizQuestionID --> link to QuizQuestion
QuizUserID --> link to a user table?
QuizAnswer
This setup assumes that you already have a user table of some kind and that the quiz answers are text.
PJ | Are we there yet?
pjboettcher.com
artsapimp posted this at 16:39 — 24th October 2001.
They have: 330 posts
Joined: Apr 2000
That is pretty much the setup I'm using. The unique identifier for each question is where I was having a problem. I think that is going to be the key.
I know there will always be 8 questions each and 5 examples per page. With this I know the unique numbers should vary from 1 To 40.
The format I've chosen now which is working correctly is:
Name=example & "," & Question
Now I should use:
Name=x & "," & example & "," & Question
(Where x is the autonumber in this application)
Is that right?
Free Math Test
Fun Math Games
artsapimp posted this at 17:04 — 24th October 2001.
They have: 330 posts
Joined: Apr 2000
I guess I'm not understanding 100%. I have created 3 variables on the receiving page:
varIdentifier 'Autonumber
varExample 'Example Number
varQuestion 'Question
I am running a for each loop referring to request.form
I am pulling the correct information but I'm not sure how to add it to my database correctly.
Below is my database structure (a little different than yours but same idea)
Examples
--------
ExampleID 'Autonumber
Example 'Memo - Explains the example
Created 'Question
Queue 'Question
Status 'Question
WorkedOn 'Question
WorkedOnSubcode 'Question
Found 'Question
Cause 'Question
Resolution 'Question
DateFrom 'Show this example starting this date
DateTo 'Stop showing this example on this date
Bonus 'Yes/No Is this a bonus question?
For each question I hvae a database with an ID and Text field for the answers available.
i.e.
Found
-----
FoundID
Found
Answer
------
Example 'ExampleID
User 'Linked to User Table
Created 'Answer
Queue 'Answer
Status 'Answer
WorkedOn 'Answer
WorkedOnSubcode 'Answer
Found 'Answer
Cause 'Answer
Resolution 'Answer
Date 'Date Entered
Time 'Time Entered
Score 'Score for this Example
How would I run through the answers and say:
From 1 through 8 add to database with it's exampleID
From 9 through 16 add to database with it's exampleID
From 17 through 24 add to database with it's exampleID
From 25 through 32 add to database with it's exampleID
From 33 through 40 add to database with it's exampleID
Thanks for any help.
Free Math Test
Fun Math Games
Peter J. Boettcher posted this at 12:55 — 25th October 2001.
They have: 812 posts
Joined: Feb 2000
Make sure you have an input box for ExampleID (probably hidden), then you will have to sort your Request.Form values so you can save them the way you want. The way I do it, is I create a hidden text box that I put all the input field names into, in the order I want, for example:
Then on my form handler page the first thing I do is parse that text box into an array:
strPassSort = Request.Form("txtSortOrder")
strPassSort = Split(strPassSort,",")
Now I have an array with the field names in the right order, now I want to assign the values to them:
ReDim SaveArray(UBound(strPassSort))
For intArrayCtr = LBound(strPassSort) To UBound(strPassSort)
SaveArray(intArrayCtr) = Trim(Request.Form(strPassSort(intArrayCtr)))
Next
Now I have another array with all the values in the right order, so now you can setup another loop to insert them into the database, if you need help with that, let me know.
PJ | Are we there yet?
pjboettcher.com
artsapimp posted this at 14:13 — 25th October 2001.
They have: 330 posts
Joined: Apr 2000
While looking at the code I understand each line. I would have never came up with this way of collecting the data and it is brilliant. Unfortunately I have changed to a different format that I think is a little easier.
I am only allowing 1 example per page. The page submits to itself so it just loops through the questions until none are available.
The first time it's loaded the querystring is empty so it pulls all exampleIDs into an array. The array is then joined into a variable and sent through the querystring. The page will load the next one each time until it's at the end where it will redirect to a finished page.
The reason I did this was to simplify the code and to make it look cleaner on the page. If you have any suggestions please let me know.
Thank you.
Free Math Test
Fun Math Games
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.