0

Intent:
I am designing a web-application with the intent to help users solve workplace problems with a group of predefined questions, distributed among 3-4 phases, that help narrow down the problem.

In each phase of the questionnaire, the user will be able to choose among a number of solutions and the solutions within next phase will be based on the choices previously made.

Each answer chosen triggers an associated animation.

User-scenario
A typical user-scenario could look like:

Q1 - What is wrong?

  • A1 - I am feeling stressed.
  • A2 - My opinions are being ignored.
  • A3 - I do not like my boss.

The user then selects option A2. And based on that choice, a question and the answers to it, will be presented to the user, as such:

Q2 - Who is ignoring your opinions?

  • A1 - My boss.
  • A2 - My coworkers.
  • A3 - Other.

..And so forth.

Specifications:

  • The questions, answers, combinations (and possibly animations) need to be stored within a database.

  • Every question and answer needs to be able to be used in multiple combinations.

  • Every animation needs to be able to be used for multiple questions.

My question:

  • How would a possible database collection of tables look, to achieve this?
1
  • This question is rather too broad for Stack Overflow, and it should have been closed back in 2016 - it would have been off-topic back then, I believe. It is essentially asking for a whole database to be designed, which is a large problem. This is why the provided answers have had to be necessarily general.
    – halfer
    Mar 27, 2018 at 0:12

2 Answers 2

0

You could use a graph for representing the problem.

Q1 -a1-> Q3
Q1 -a2-> Q2 -*-> Q3
Q1 -a3-> Q3

Tables:

Questionnaire
 - Id
 - Name

Question
 - Id
 - Title

Response
 - Id
 - Title

QuestionnaireQuestions
 - QuestionnaireId
 - QuestionId

QuestionResponse
 - QuestionnaireId
 - QuestionId
 - ResponseId
 - NextQuestionId
 - Animation

FK from QuestionResponse(QuestionnaireId, QuestionId) to QuestionnaireQuestions(QuestionnaireId, QuestionId)

10
  • Would the graphs purpose simply be to visualize it the questionnaire process? Also, your tables makes a lot of sense for me, however, how would you tie multiple responses to each question? And what exactly does the Questionnaire table represent? Lastly, thank you very much for your quick answer!
    – Nenn
    May 18, 2016 at 10:48
  • It doesnt cover multiple choice but you could use a bitmap instead of ResponseId in QuestionResponse table. Basically the first response value is 1, the second 2 the third is 4 and so on (2 pow N). You add the values of all the selected responses. That means you will get a 5 if first and third response are selected. Any combination of responses have a unique aggregated value by adding its individual values. May 18, 2016 at 11:32
  • I am using phpmyadmin to work with my database, a bitmap index is not possible here, as far as I can see. I have however come closer to a solution, except that I cannot find a way to specify, in a separate table, which responses (up to 8) fit under a specific question in a single row? Without having to do 8 ResponseID columns? Do you know any way to do this? Again, thank you very much for your time and help.
    – Nenn
    May 18, 2016 at 13:53
  • I dont mean a bitmap index... I mean an integer column storing a number that indicates the combination of anwsers. Only first => 1, only second => 2, first and second =>3, only third=> 4 ..... this is a bitmasc because in binary 101 is 5 and indicates first and third were selected (they have a 1 instead a 0). I meat this: stackoverflow.com/questions/2882276/… May 18, 2016 at 15:18
  • That does sound like it would fix my problem. I sadly, however, have no idea how I would go about making something like that work in reality. I am very new to database construction and don't know a thing about binary. Would it be possible in some other way? Or can you maybe draw up an example for me? I would appreciate both very much!
    – Nenn
    May 18, 2016 at 16:39
0

You have a predicate that identifies which questions exist. You have a predicate that identifies which answers exist [for which questions]. You have a predicate that identifies which answers [for which questions], when given, lead to a followup question.

Specifically about " the solutions within next phase will be based on the choices previously made."

Since there is no way to predict how many preceding choices play a role in determining the subset of possible answers for any followup question, this aspect of the problem is impossible, or as good as impossible, to model as a number of columns in some table.

This forces you to disambiguate each possible "who is ignoring you" that has a distinct set of possible answers, as a SEPARATE question.

2
  • For this specific project, only 3 or maybe 4 phases will be used, this would mean that there would only be 3-4 preceding choices that play a role when determining the possible answers. Is it not possible then, to use the combination of preceding choices made to determine which question should be asked and which answers will be tied to it? Instead of having it tied to the specific question? I am relatively new to database structure so I apologize in advance if I have misunderstood your answer.
    – Nenn
    May 18, 2016 at 10:54
  • OK. Let's say I'm going to ask question 7 after having asked qns 1 and 4, and after having obtained answers 1a and 4c. Question 7 can also be asked after having asked qns 1 and 4 with answers 1d and 4a, with a different answer set for Q7 compared to the first case. Q7 can also be asked after having asked qns 1,2,3,6 with answers 1b,2b,any for 3, 6a/d. Once again with a different possible answer set for Q7. So we have three distinct possible answer sets for Q7. Write the single query that determines the answer set precisely for each of the possible paths to Q7. (Don't try, you'll fail.) May 18, 2016 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.