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?

Thanks
:) SD
LVL 11
sciber_dudeAsked:
Who is Participating?
 
nabsolCommented:
Hi
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
0
 
dukestaTAICommented:
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)">
      <ol>
      <%Do while not rs.EOF%>
      
      <li>
            <%=rs.fields("Question")%></li><br>
            <%  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>
                              
                              <%rsSurvey.MoveNext
                              
                  Loop
            %>
            
            <br>
            
      <%rs.MoveNext
      Loop%>
0
 
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
0
 
sciber_dudeAuthor Commented:
This is awesome! Thank you.

:) SD
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.