Online continuation of the article
We have finished the file design, and written the surveycode.asp code. Now we're done.
Other documents. When you finish these files, don't forget the program flow that you wrote before, if you don't remember it, it's best to print
A copy out to look at.
I. Statistical results
First, we're going to complete the display statistic results that are most closely related to surveycode.asp survey_vote.asp
File. At the end of the previous article, we have explained some of the parameters identified in the surveycode.asp.
Statistical results survey_vote.asp
<!--#include file= "inc.asp"-->
<title> Survey Statistics Results </title>
<link rel= "stylesheet" href= "Main.css" type= "Text/css" >
<body>
<%
The previous sentence first joins the include file, referencing the function.
Id=request.querystring ("id") ' Get querystring parameter ID
opendb my ' connection database
If id= "" then "if not, then it is not directly to see the result
Id=request.form ("id") ' get form parameter ID
If id<> "then" if there is a value, it is to be counted first
Surveycount () calls the statistics subroutine
End If
End If
If id<> "" Then
Disp_survey () ' Whatever it is, the results are displayed at the end
End If
Closedb my ' closes the database
'-----Statistics subroutine-----
Sub Surveycount ()
If session ("SURVEY_OK") = "then" If you haven't voted yet
No=request.form ("res") ' Gets the number of the answer
If no<> "" Then
' Define the SQL statement so that the number of answers submitted is +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
'------------------
'---Display the result subroutine---
Sub Disp_survey ()
' Define SQL statements, get investigated questions
Sql= "Select Survey_question from Survey where survey_id=" & ID
Searchtable my,sql,rs ' Execute query
Question=rs ("survey_question") ' Save the problem in question
CloseTable rs ' Close table
' Define the SQL statement and get the sum of the number of answers
Sql= "Select sum (vote_count) as total from Survey_vote where vote_id=" & ID
Searchtable My,sql,rs
Total=rs ("Total")
CloseTable rs ' Close table
' Define the SQL statement, get all the answers to the text part and the number of votes
Sql= "Select Vote_answer,vote_count from Survey_vote where vote_id=" & ID
Searchtable my,sql,rs ' Execute query
' Table to output tables below
%>
<table width= "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= "align=" height= "center" > Answer </td>
<TD width= "align=" height= "center" > Voter turnout </td>
<TD width= "align=" "center" height= > ratio </td>
<TD width= "align=" center "height=" > Votes </td>
</tr>
<%do While not rs.eof
If Total=0 Then
Percent=0 ' If no one votes, the percentage is 0
Else
Percent=int (RS ("Vote_count")/total*10000)/100 ' percent calculation
End If
%>
<tr>
<TD width= "align=" "Center" ><%=rs ("Vote_answer")%></td>
<TD width= "align=" "Left" >
<table border= "0" width= "<%=percent%>" bgcolor= "#CCCC00" height= "ten" >
<tr>
<td></td>
</tr>
</table>
</td>
<TD width= "align=" "Center" ><%=percent%>%</td>
<TD width= align= "center" ><%=rs ("Vote_count")%></td>
</tr>
<%
Rs.movenext
Loop
%>
<tr>
<TD colspan= "4" > To <%=now ()%>, total <%=total%> vote
<a href= "Javascript:window.close ()" > Close window </a>
</td>
</tr>
</table>
<%
CloseTable rs ' Close table
End Sub
'------------------
%>
</body>
In the display of the voting process, we use the session variable SURVEY_OK to indicate whether the vote has been voted. In addition, this shows
In the statistics, the CSS file is used to control the style of the table, you can join according to your own request.
Ii. listing the status of all investigations
Now that we're done with survey.asp, its main task is to list all the survey statuses, including:
1, the investigation of the problem, linked to the voting form page (directly written on this page);
2, the starting time of the investigation;
3, the end of the investigation time;
4, the investigation of the status: Not started, in progress, has ended;
5. Number of votes in the survey;
6, the type of investigation, radio or multiple election;
7, also give a link to view the cast