Copy link to clipboard
Copied
Hi guys,
Im experimenting with calculations on a site but im not sure whats the right way to go about it.
the result im looking for is this,,
Im setting up a personality test on the website where the questions he answers should classify him into one of 4 groups.
my thoughts are to keep it simple, every question he answers should have a +1 effect on the certain group in question and then at the end of all the questions display the result of the group that has the largest count.
now some told me i should use javascript which im not very familiar with,
others said i should be able to do the calculations in php before the result is sent to the database
but i also thought of the possibility to send all into uncalculated to the db and then just retrieve the right result,
would like to hear your opinions on this,
or if you think there is a easier way than my "+1 effect"
thanks in advance!
Copy link to clipboard
Copied
One way would be to associate each question with a group.
Create an array with 4 elements say G(0), G(1), G(2), G(3) Set it to zero.
for question = 1 to number of questions
Ask a question
Each time a question is answered correctly, increment value of the associated array group element (1) to (4) by 1.
Until you have asked the first round of questions.
So now you have a set of values in each element. Problem is how to find the largest. Especially if you have a tie.
Sort the array to set them in order ascending- see :http://www.php.net/manual/en/function.asort.php
set $winner to the first groups reference ( this will always be 0,1 2 or 3 and should contain the winner unless there is a tie)
If the lst two elements in the sorted list are not equal
set $winner to the 1st elements reference (if its G(3) set it to 3, not the value of G(3))
else (you have a tie)
repeat
set the other two elements to zero
ask a question
increment the matching group element
sort the array
compare the values of the two top elements
until the values of two top elements are not equal
set the value of $winner to the 1st elements reference (if its G(4)set it to 4, not the value of G(4))
store $winner in your database
Hope this makes sense - it took a while to work out and it still needs coding.
The other way is to ask your questions and save them in the database as you go along. At the end of stage one, do a select all from groups, order by group value
You may then have a tie, so you would need to ask more questions as deciders and do it again.
Either way, ist an interesting project.
I'm off to bed!
Copy link to clipboard
Copied
>but i also thought of the possibility to send all into
>uncalculated to the db and then just retrieve the right result,
Ding ding ding! You got it right. Store the raw data, then you can easily do the calculation using either SQL or PHP. If you just store the results, you lose valuable information and makes it difficult to do more in depth analysis. Of course, it's important that your database structure is setup correctly. I would set it up similar to a survey database:
UserResponseTable:
userId
questionID
response
QuestionTable:
questionID
questionText
groupID