Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Survey branching tutorial

Posted on 2017-04-06
11
Medium Priority
?
149 Views
Last Modified: 2017-04-11
Does anyone know of a good tutorial on building a survey system using PHP.

I'm having trouble wrapping my head around how branching on a survey works (where some questions are hidden unless the answer to another equals something), in particular how the concept would work in terms of storing that data in a table and then using it at run time.
0
Comment
Question by:Stephen Forlance
  • 6
  • 3
  • 2
11 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 42082694
I am sure there are many patterns out there for this. I use the following method

I have a routing table that allows me to specify
a question
an answer
a destination
a value to say equal or not equal

On each question I check that table - I look for the question number, get the answer and check to see if the actual answer for that question matches. If it does I check the equal not equal value. If this is set to NotEqual and the answer given does NOT match the answer value in the table then I jump to the next question. If they are equal I allow the current question to continue - vice versa if they values must be equal.

All questions have a stack to say where they came from so that if you branch and someone hits the back button you go back to the branch point not the previous question in the section.

Best I can do for now - if you want to pursue it more post back and I will see if I can put a sample together.
0
 

Author Comment

by:Stephen Forlance
ID: 42082715
Any samples you could give would be great
thanks
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 42082734
Any particular reason you are building your own and not using something like Moodle or similar?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Stephen Forlance
ID: 42082740
The reason is basically because I want to know the system inside and out, and secondly its something that Ive been thinking about for few years now, and its its at the edge of my understanding, so Id like to conquer it :)
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 42082758
How far have you got? If you are just starting out then you have a journey ahead of you. Our survey engine has been developed over the last 17 years - we keep refining it to cater for new requirements - so the question is how much of a head start do you need - because it could take a while to provide a demo from scratch.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 42082767
My sense is that reinventing your wheel when a well-known solution already exists is probably an antipractice.  Go Pro on SurveyMonkey!
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 42082802
My sense is that reinventing your wheel when a well-known solution already exists is probably an antipractice.
Might be stuck with the Model 'T' if we always adopted that approach :)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 42082836
I think SurveyMonkey is one of the tools Experts-Exchnage has used for its surveys.  If SurveyMonkey were stuck in the steady state with respect to time, I would agree about the Model T, but I think they are a going concern with active development.  IIRC, ConstantContact has surveys, too.  And Google.
https://www.experts-exchange.com/questions/28934183/Survey-software.html
https://www.experts-exchange.com/articles/18199/Top-5-Best-Practices-for-Conducting-Surveys-with-Google-Forms.html
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 42083173
Fine, but there is never a good reason to innovate. By continually revisiting products / problems we find other products or improve existing one.
SM is a good tool but it left a gap that Qualtrics was able to fill.
0
 

Author Comment

by:Stephen Forlance
ID: 42084105
Ive figured out the basics in terms of questions and options etc, but what i was trying to work out is how to store the branching information in  a database and then call it to logically effect the flow of the survey.
0
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 42084683
Then the answer is dependent on your current implementation - I can't give code that is guaranteed to work as it will depend entirely on your current question engine.

What I can do is describe (as I have above) a process by which you can do this - to recap
1. Each question needs to store where it came from - what was the previous question. My engine stores all data about a question as a JSON string in the database. The entire survey results are saved as a JSON structure. This allows me to change the way the engine works without having to mess with the db - I can add new meta data fields etc. The draw back is extraction is a bit more complex but after weighing up the pros and cons of each approach - the JSON approach has made my engine extremely flexible and easy to extend.

So how you store your data is important - in your case you will need to make a provision for where you came from.

2. Before each question is rendered you check your routing table - how you set this up is also a matter of preference. In my case I set it up as a
Survey ID | Question | Answer Number | Answer Value | Target Question | Route If Equal | rank

When I land on a question I search the routing table for all routes that match this question (Question) and order them by rank.
I then check each of the answers in turn matching the answer from my data against the answer specified in the route using the "Route if Equal" flag to determine if I am looking for value equal or not equal. If the expression is true I jump to the Target Question - and repeat the process until no more routes cause a jump.

3. When I have finally explored all the routes I save the last question ID to the previous question field of the final target question the route led to.

Note with 2 - having the entire survey in a JSON structure makes it easy to lookup previous values and set prev question values - you would need to adapt this to your situation.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question