Learn to do online surveys with Me (ii)

Source: Internet
Author: User
Tags exit modify query
Online continuation of the article
In the previous article we have analyzed the function of the online survey, the structure of the database, and some
Function. The main task of this article is the design of the document. Design how many files to make up this online
Surveys, and what tasks each document shares. and write down the main process of these files to facilitate the following code
Write.

First, document design
According to the traditional idea, we always design the online survey into three parts, one is to show the questionnaire;
is to show the results of survey statistics, and third, background management. And in practical applications, we will find that the display questionnaire
Often in a Web page, the display result is usually a pop-up window. Background management is done through another
Link or the login form. To make it easier to use online surveys, we've shown the questionnaire section
Write a JS script so that the Web page that needs to display the questionnaire is freely invoked by referencing the script. Good
Look at the file design
1, inc.asp contains files. The main function library
2, surveycode.asp display questionnaire procedures. Use a script in the main page to call it.
3, survey.asp questionnaire list program. Lists the status of all surveys.
4, survey_vote.asp Display survey results procedures. The problem with the survey is represented by the parameter.
5, survey_manage.asp management procedures.

Here, we skip the page design, because style design is not what we want to say, so about web
Page style, layout, CSS and so on, please design their own.

Second, the document flow
Write out the main process of the program, can be more convenient for later modification and expansion, transplantation. It's more important here.
is what subroutines to write in the program, and how to schedule these subroutines.

1, surveycode.asp Display survey form
<%
' Get querystring parameter, ID indicates survey number
' Judging the correctness of parameters
' Judge whether the investigation is in the validity period.
' Read survey questions, types
' Output survey answers, and generate survey forms
' Close database and table
%>


2, survey.asp Show all investigation status
<%
' Read the database
%>
' Show all survey status and add links


3, survey_vote.asp display statistical results.
Here are two features, one is not submitted to the display, the second is to submit the answer after the statistics, and then show
Results. If you do not take parameters, this is the first way. can also be divided into two files to complete.
<%
' Get the parameters. ID indicates survey number all data is from form
' To determine whether there are parameters, there are statistics first
' No, show it directly.
' Statistics subroutine
%>
' Show Child programs


4, survey_manage.asp management procedures.
The management part is more complicated, to realize more functions. Let's first list the functions of management:
1) Admin login. Managed only after logging in
2 Exit Login. Secure exit after completion of administration.
The management of the survey is:
3) Add a survey. and increase the answer to the investigation.
4) Modify a survey. Modify content, time, type, investigate the content of the answer, add, delete
5) Delete a survey. You cannot delete an ongoing investigation.

To design its process for these functions
<%
' Get the parameters. Action represents actions, respectively, corresponding to the above functions.
' Move to the appropriate subroutine according to the action
' Login subroutine
' Exit Login subroutine
' Execute additional investigation questions subroutine '
' Execute increased survey answer subroutine
' Execute modification Survey subroutine questions and answers together
' Perform the delete survey question subroutine
' Perform delete survey answer subroutine
<%
' To determine whether to log in, not to display the login form
' Show the corresponding form according to the action
' Show all survey subroutines
' Displays a single survey subroutine. Questions and Answers show together
' Show increased survey subroutine.
' Show Login Form
%>


Third, code writing
After doing the process design, the writing code is more organized. Let's start with the simple. In writing code
Before, we have to enter some records in the database in order to do the test. First, add a survey question, and a few
Investigate the answers and enter some statistics manually.
Let's write the surveycode.asp that shows the survey form. This file is called on another page,
So we write JS and VBS in a mixed way. When called, you can put it in a table with the following statement:
<script language= "JavaScript" src= "surveycode.asp?id=1" ></SCRIPT>

According to the above process, before displaying the form, we must first determine whether the investigation exists, whether it is in progress. Other than that
To submit a hidden parameter in the form to indicate the problem number (ID) of the survey, when the answer is submitted, the
Is the number of the answer Vote_no
FileName surveycode.asp
<!--#include file= "inc.asp"-->
<%
Id=request.querystring ("id")
If id<> "" Then ' if there are parameters
Opendb my ' join database
Sql= "SELECT * from survey where survey_id=" & ID "query statement
searchtable my,sql,rs ' query database
If not rs.eof then ' if there is a record of this investigation
Question=rs ("survey_question") ' read out the problem
Surveytype=rs ("Survey_type") ' read out answer type
Stime=rs ("Survey_stime") ' read out start time
Etime=rs ("Survey_etime") ' read out end time
CloseTable rs ' Close table
If Stime<now () and Etime>now () then ' if the investigation is in progress
' Output survey form below
' First output forms and issues, form submission to survey_vote.asp
%>
document.write ("<form action= ' survey_vote.asp ' target= ' _blank ' method= ' post ' >");
document.write ("<table border= ' 1 ' cellpadding= ' 2 ' cellspacing=0 '" #000000 ");
document.write ("bordercolordark= ' #ffffff ' width= ' 100% ' align= ' center ' ><tbody>");
document.write ("<tr><td colspan= ' 2" align= ' Center ' ><b><%=server.htmlencode (question)%> </b></td></tr> ");
<%
Sql= "Select Vote_no,vote_answer from Survey_vote where vote_id=" &id "Query answers SQL
Searchtable my,sql,rs ' Execute query
If not rs.eof then ' if there is an answer, the output
For I=1 to Rs.recordcount
%>
document.write ("<tr><td align= ' right ' ><input name= ' res ' type= '");
<%
If Surveytype then ' judgment type, show single or multiple selection
%>
document.write ("checkbox");
<%else%>
document.write ("Radio");
<%end if ' The text of the output answer and the value submitted (VOTE_NO)%>
document.write ("' Value=<%=rs" ("Vote_no")%>></td><td><%=rs ("Vote_answer")%></td ></tr> ");
<%
Rs.movenext
Next
' The following sentence outputs a hidden parameter, passing the problem number (ID)
' Use a JS function to define the link after clicking the view
%>
document.write ("<tr><td colspan= ' 2 ' align= ' center ' ><input Typ



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.