0

Hi

Hope,everyone is doing good out there.

I need some help regarding which strategy to use for one of my projects.

Here are the project details

I want to generate PDF forms, by gathering data from user.There are different questions to ask and based on each answer,we will ask next question.i.e Where do you live? If s/he reply USA, next question will be regarding USA,if s/he reply Outside USA,next question will be different. I'll use FPDF to generate PDF on the go.

But my question is how to implement questionnaire.Where should we store the values, either in session or Mysql as we will use these values in PDF.

Need your urgent help.

4
Contributors
6
Replies
47
Views
2 Years
Discussion Span
Last Post by baloch123
1

First you will need to create workflow, so starting from first question to the end.
When you create that you will see if you have a lot of branches for one question or not.
If yes you can do it in few ways:
- Store values in session then check is session value USA then start new branch of questions.
- And to store questions in MySql

I think second solution is better because of this:

If you use sessions:
If your user in the middle of questions goes out turn of his browser you will end up with nothing.
If you want to wait user finish everything then store it in db that wouldn't happen.
What is good thing about Session is that you store in DB just once so your server will be faster.
That describes problem for continually storing in DB you will make your server slower.
But even it will be slower you will have some data in DB if user leave it...

Both of this approach have good things and bad, I will use MySql because nowdays servers have good speeds so it will not affect your website that much.
For implementing I suggest JavaScript and JQuery...

0

Thanks milil for your reply.

Can you send me any tutorial regarding this?

But at start of questionnaire user don't have login details,it will be registered after completing questionnaire and then we will generate PDF docs and ask them to register and download your PDF doc.

0

I have multiple(40) questions,and i want to ask one question at a time,

How can i switch between questions?

Can you please suggest?

1

Very good advice on storing the data.

How can i switch between questions?

Well that depends on what questions you would like to ask.

You need to come up with a diagram of all the questions you could ask, depending on what answers you get. For instance:

Name? --> Age? --> Country? -(USA)-> State? -->
                            -(UK)->  UKquestions ->

Once we know that much, we can then decide how we're going to write the program. This is completely dependant on what sort of questions and possible answers you have.

Possible method as follows:

Lets say you have a load of pre-defined questions and a selection of answers.

DB.questions:

id - Primary Key
title - Question
previous_id - Parent question
previous_answer - Answer given to parent question

If we used the above diagram + DB structure, and the country question is id = 3. We then have a record in the db like this: 4, "What state are you in?", 3, "USA".

Next, someone enters USA as their country, so you search the DB for a question with a parent_id = 3 (since we've answered the country question), and an previous_answer = "USA". We then use the id & title of the question we find, to provide the question and the parent id for the next question.

Hope that makes sense.

Edited by mattster

1

These types of projects become very convoluted very quickly - especially when you need to make changes to questions or if progress is non-linear or dependent on a combination of previous answers with common intermediate questions.

Drawing a diagram is a great idea. The parent_id is often quoted and can be effective. Apart from the "adjacency list" method, you may want to have a look at the "nested sets" method. Instead of repeating myself, here's a thread where I discuss it with iamthwee:

https://www.daniweb.com/web-development/php/threads/479889/build-menu-list-from-array

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.