Tutorials to .com

Tutorials to .com » Asp » Examples » Learn to use ASP to do an online survey

Learn to use ASP to do an online survey

Print View , by: iSee ,Total views: 14 ,Word Count: 2983 ,Date: Mon, 27 Apr 2009 Time: 7:48 AM

-------------------------------------------------- ---------------
Field Type Length Description
-------------------------------------------------- ---------------
Automatic ID manage_id - useless here that the future expansion of use
15 text manage_username administrator user name
manage_password text administrator password 15
-------------------------------------------------- ---------------

-------------------------------------------------- ---------------
Field Type Length Description
-------------------------------------------------- ---------------
Automatic ID survey_id - incremental, primary key, there are no duplicate index
255 survey questions survey_question text
whether survey_type - type, whether: the radio is: choose
survey_stime date - a long date, start time
survey_etime date - a long date, end time
-------------------------------------------------- ---------------

Field Type Length Description
-------------------------------------------------- ---------------
Automatic ID vote_no - incremental, primary key, there are no duplicate index
vote_id long integer - The index of overlap and 0 decimal places
Text 100 survey vote_answer answer
vote_count long integer - the number of voting
-------------------------------------------------- ---------------

''************************************************ *******************
asp function''Universal database
''************************************************ *******************
database constant''
databasename = "survey.mdb"''database name, if renamed, then modify the line in the
''************************************************ *******************
Open database''
sub opendb (connect)
set connect = server.CreateObject ( "ADODB.connection")
connect.ConnectionString = "DRIVER = (Microsoft access Driver (*. mdb)); DBQ =" & _
server.MapPath (databasename)
connect.Open strconn
end sub
''************************************************ *******************
Closed database''
sub closedb (connect)
connect.close
set connect = nothing
end sub
''************************************************ *******************
Open a single table read''
sub opentable (connect, tbname, myrs)
set myrs = server.createobject ( "ADODB.recordset")
rssql = "select * from" & tbname
myrs.open rssql, connect, 1,1
end sub
''************************************************ *******************
The closure of a temporary table''
sub closetable (rs)
rs.close
set rs = nothing
end sub
''************************************************ *******************
Query the database''
sub searchtable (connect, sql, rs)
set rs = server.createobject ( "ADODB.recordset")
rs.open sql, connect, 1,1
end sub

And change the database query''
sub changetable (connect, sql, rs)
set rs = server.createobject ( "ADODB.recordset")
rs.open sql, connect, 1,3
end sub

display information for debugging''
Sub w (msg)
response.write msg
end sub

Disruption''procedure for debugging
sub userstop ()
response.end
end sub
%>

Access querystring parameters'', id, said the survey numbers
Parameters to determine the correctness''
Investigation''to determine whether the validity of.
Investigate the question of''to read, type
Output''survey answers, and generate survey form
Close the database and table''
%>

''Read a database
%>
<html>
Shows the status of all investigations''and adding links
</ html>

Obtain the parameters''. id number that all the data from the survey form
To determine whether''there are parameters, there is the first statistical
Show that''there is no direct
Subroutine statistics''
%>
<html>
Display subprogram''
</ html>

Obtain the parameters''. action that the action, corresponding to the above functions.
''According to the corresponding action to turn the subroutine
Sign subprogram''
Logout''Subroutine
The question of the implementation of the investigation''Subroutine
The answer''to investigate the implementation of the enhanced subroutine
Implementation of amendments to the investigation''subroutine modified with questions and answers
Investigation''to remove the issue of the implementation of subroutine
The answer''to investigate the implementation of the deletion of Subroutine
<html>
<%
Log in to determine whether''there is no login form is displayed
Show''in accordance with the corresponding form action
Investigation''of all subroutines
Investigation''showed that a single subroutine. Questions and answers displayed
Subprogram''survey showed an increase.
Show login form''
%>
</ html>

, We have some input in the database records, in order to do the test. First to add a survey question, and answer a few surveys and some statistical information entered manually.

<%
id = request.querystring ( "id")
if id <> "" then''if there are parameters
database connection opendb my''
sql = "select * from survey where survey_id =" & id''query
searchtable my, sql, rs''query the database
if not rs.eof then''if there are records of this survey
question = rs ( "survey_question")''reading problems
surveytype = rs ( "survey_type")''to read out the answer to the type of
stime = rs ( "survey_stime")''to read out the start time
etime = rs ( "survey_etime")''to read out the end of time
Close Table closetable rs''
if stime <now() and etime> now () then''if the investigation is in progress
Output the following survey form''
First''and the issue of output form, the form submitted to the survey_vote.asp
%>
document.write ( "<form action=''survey_vote.asp'' target=''_blank'' method=''post''>");
document.write ( "<table border =''1''cellpadding =''2''cellspacing = 0''bordercolorligh =''# 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''answer to the SQL query
searchtable my, sql, rs''execute the query
if not rs.eof then''if there are answers on the output
for i = 1 to rs.recordcount
%>
document.write ( "<tr> <td align=''right''> <input name =''res''type =''");
<%
if surveytype then''to determine the type of the radio show more than the election or
%>
document.write ( "checkbox");
<% else%>
document.write ( "radio");
<% end if''the following text of this output and submit answers to the value (vote_no)%>
document.write ( "''value = <% = rs (" vote_no ")%>></ td> <td> <% = rs ( "vote_answer ")%></ td> </ tr>");
<%
rs.movenext
next
The following''a few output parameters of a hidden, passing the issue of ID (id)
''With a JS function after the definition of Click to view the link
%>
document.write ( "<tr> <td colspan=''2'' align=''center''> <input type =''hidden''name =''id''value =''<%= id% >''>");
document.write ( "<input type=''submit'' class=button value=''''>");
document.write ( "<input type = button class = button value =''see''onclick =''jump (<% = id %>)''>");
document.write ( "</ td> </ tr> </ tbody> </ table> </ form>");
function jump (id) (
window.open ( "survey_vote.asp? id =" + id, "survey")
)
<%
end if
end if
end if
closetable rs
closedb my
end if
%>

<html>
<head>
<title> survey results </ title>
<link rel="stylesheet" href="main.css" type="text/css">
</ head>
<body>
<%
First sentence''containing the papers quoted function.
id = request.querystring ( "id")''access querystring parameter id
opendb my''to connect the database
if id = "" then''If not, is not directly see the results of
id = request.form ( "id")''access to form parameters id
if id <> "" then''if there is value, it is first and Statistics
surveycount ()''statistical subroutine call
end if
end if
if id <> "" then
disp_survey ()''Either way, the end result will be displayed
end if
closedb my''close the database

sub surveycount ()
if session ( "survey_ok ")="" then''if not to vote
no = request.form ( "res")''to be the answer to the number
if no <> "" then
The definition of SQL statement''so that the number of answers submitted +1
sql = "update survey_vote set vote_count = vote_count +1 where vote_no = in (" & no & ")"
my.execute sql
end if
session ( "survey_ok") = "ok"
end if
end sub
''------------------

sub disp_survey ()

sql = "select survey_question from survey where survey_id =" & id
searchtable my, sql, rs''execute the query
question = rs ( "survey_question")''to keep the issue in question
Close Table closetable rs''
The definition of''SQL statement, the total number of answers
sql = "select sum (vote_count) as total from survey_vote where vote_id =" & id
searchtable my, sql, rs
total = rs ( "total")
Close Table closetable rs''

sql = "select vote_answer, vote_count from survey_vote where vote_id =" & id
searchtable my, sql, rs''execute the query
Form''below to output tables
%>
<table width = "500" border = "1" align = "center" cellpadding = "2" cellspacing = "0"
bordercolorligh = "# 000000" bordercolordark = "# ffffff">
<tr>
<td colspan="4" align="center"> <b> survey results </ b> </ td>
</ tr>
<tr>
<td colspan="4"> <b> survey questions: <% = question%> </ b> </ td>
</ tr>
<tr>
<td width="150" align="center" height="20"> an answer </ td>
<td width="150" align="center" height="20"> turnout </ td>
<td width="100" align="center" height="20"> ratio </ td>
<td width="100" align="center" height="20"> votes </ td>
</ tr>
<% do while not rs.eof
if total = 0 then
percent = 0''if no one votes, then the percentage is 0
else
percent = int (rs ( "vote_count") / total * 10000) / 100''percentage
end if
%>
<tr>
<td width="150" align="center"> <% = rs ( "vote_answer ")%></ td>
<td width="150" align="left">
<table border = "0" width ="<%= percent%> "bgcolor =" # CCCC00 "height =" 10 ">
<tr>
<td> </ td>
</ tr>
</ table>
</ td>
<td width="100" align="center"> <% = percent %>%</ td>
<td width="100" align="center"> <% = rs ( "vote_count ")%></ td>
</ tr>
<%
rs.movenext
loop
%>
<tr>
<td colspan="4"> to <% = now ()%>, there were <% = total%> votes
<a href="javascript:window.close()"> Close Window </ a>
</ td>
</ tr>
</ table>
<%
Close Table closetable rs''
end sub
''------------------
%>
</ body>
</ html>

<!--# include file = "inc.asp" ->
<html>
<head>
<title> list of online survey </ title>
<link rel="stylesheet" href="main.css" type="text/css">
</ head>
<body>
<%
id = request.querystring ( "id")''to obtain the parameters
if id <> "" then''if there are parameters in the form of the survey showed
response.write "<SCRIPT Language=''JavaScript'' SRC=''surveycode.asp?id="&id&"''> </ SCRIPT>"
Otherwise, call the subroutine else''shows the state of
disstat ()
end if

sub disstat ()
opendb my''to connect the database
opentable my, "survey", rs''open the table directly
The following table shows''with each record
Table''to show that the first
%>
<table width = "760" border = "1" cellspacing = "0" cellpadding = "2"
align = "center" bordercolorligh = "# 000000" bordercolordark = "# ffffff">
<tr>
<td colspan="8" align="center"> <b> list of online survey </ b> </ td>
</ tr>
<tr>
<td width="50" align="center" height="20"> ID </ td>
<td width="200" align="center" height="20"> survey </ td>
<td width="50" align="center" height="20"> type </ td>
<td width="140" align="center" height="20"> time from Kai </ td>
<td width="140" align="center" height="20"> the end of time </ td>
<td width="50" align="center" height="20"> state </ td>
<td width="80" align="center" height="20"> has the votes cast </ td>
<td width="50" align="center" height="20"> Show </ td>
</ tr>
<%
Output for each record the following''
do while not rs.eof
''First read out each of the fields
id = rs ( "survey_id")
question = rs ( "survey_question")
Read out the type of''
if rs ( "survey_type") then
stype = "Multiple"
else
stype = "radio"
end if
stime = rs ( "survey_stime")
etime = rs ( "survey_etime")
Determine the status of''
if now () <stime then
stat = "not started"
else
if now <etime then
stat = "ongoing"
else
stat = "closed"
end if
end if

sql = "select sum (vote_count) as total from survey_vote where vote_id =" & id
searchtable my, sql, tmprs''inquiries
total = tmprs ( "total")
Close Table closetable tmprs''
''Following a record output
%>
<tr>
<td align="center" height="20"> <% = id%> </ td>
<td height="20">
<a href = "survey.asp? id = <% = id %>"><%= question%> </ a>
</ td>
<td align="center" height="20"> <% = stype%> </ td>
<td align="center" height="20"> <% = stime%> </ td>
<td align="center" height="20"> <% = etime%> </ td>
<td align="center" height="20"> <% = stat%> </ td>
<td align="center" height="20"> <% = total%> </ td>
<td align="center" height="20">
<a href = "survey_vote.asp? id = <% = id%>" target = "_blank"> View </ a>
</ td>
</ tr>
<%
rs.movenext''a move to the next, the cycle
loop
%>
</ table>
<%
Close Table closetable rs''
closedb my''close the database
end sub
''----------------------
%>
</ body>
</ html>


ASP examples Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.