Creating Dynamic Surveys - The Concept

I need a simple example (either ASP or PHP code) of how to

1. Store the survey questions in a database based on templates
2. Display these questions on a form dynamically
3. Code for how to save reponses on that form

Can anyone help me with that?

:) SD
LVL 11
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is a sample of classic asp code that code that does a portion of what you are asking.  However you are asking for a full blown application which i would be glad to build for you on a consultant basis in either Classic ASP or ASP.NET.

The code below loops through records retrieved from a database connection(not shown) and displays the questions on a form dynamically. The process of posted data(not shown) writes the answers back to the databas in a user answer table for later review.  There are much more efficient ways of doing this with ASP.NET as well. I hope this answeres you question.

<form action="surveyprocess.asp" Method="post" onSubmit="return valid(this)">
      <%Do while not rs.EOF%>
            <%  ID = rs.fields("id")%>
            <%  rsSurvey.MoveFirst
                  Do while not rsSurvey.EOF
                              Rating = rsSurvey.fields("id")
                              Description = rsSurvey.fields("Description")%>
                              <input type="radio" name="Q<%=ID%>" Value="<%=Rating%>">&nbsp;<%=Description%><br>
sciber_dudeAuthor Commented:
Thank you for the code. I understand what you say. What would be the database structure for this kind of table?

:) SD
PS: Upped the points to 500
I had worked for a site to create survery builder. So may be i can help you in detail.

1. About Database Tables:

               ::Table Names::
              1. "Survey" (This table will store all the surveys; id, columns name, creator, status etc)
 Questions created:
              2. "Question" (This table will store questions ; id, survey_id, question_text, type_of_question (for mcq, t/f/ descriptive etc), required(if option is optional or required))
Responses gathered.
             3. "Response" This table will store responses each with its own id called ( response_id, survey_id, time_taken, response_date )

              4,5,6. For each type of question different table. i.e. To store true/false quesiton a table "tfResponse" (id, survey_id, response_id, question_id, trueorfalse), second may be "descriptiveResponse" (id, survey_id, response_id, question_id, description) and third for mcq responses.

Now when someone will create survey you will enter values in Question table (question_text, question type) . We had given interface to user so that user can select which quesion he wants to create and what are its options if its mcq.

When some will want to take survey pick all the quesion by survey_id which is in quesion and then show all the quesions according to the type.

if ($question_type == "tf")
   //output question text
   //output two radio buttons and two values
else if ($question_type == "descriptive")
   //output question text
   //output multiline or single line text box; you can also get when user was creating survey

To store responses simply use those "response" tables to store one entry in response table and get response_id and put that id in tf, descriptive tables.

Afterall you can also generate reports. :) Hope this helps

If need to know more in this topic or anything else feel free to post :)
By Nab

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sciber_dudeAuthor Commented:
This is awesome! Thank you.

:) SD
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.