Creating Dynamic Surveys - The Concept

Posted on 2006-04-04
Last Modified: 2012-06-21
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
Question by:sciber_dude
    LVL 4

    Assisted Solution

    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>
    LVL 11

    Author Comment

    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
    LVL 6

    Accepted Solution

    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
    LVL 11

    Author Comment

    This is awesome! Thank you.

    :) SD

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    When pages do not download correctly, and you don't know why, the first thing you do is to look at the HTML source code of that page, but not all the downloaded files appear always clearly. If your source includes a javascript that computes the name…
    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now