Development of Web Survey (voting) system using ASP technology (3)

Source: Internet
Author: User
Tags array definition html form join variables
Web| vote-Vote three, the formation of survey form and the analysis of results
Author: Cactus Studio

Pollwriter.asp first examines the form variables, including the survey item name Pollname and (optionally) the string linktext and Linkurl,linktext and Linkurl describes the URLs that are displayed after the user submits their voting results. The script then creates and executes the SQL command that extracts the recordset from the S_ table and the A_ table of the specified survey project, and then iterates through the recordset to format the radio buttons, check boxes, and other hint text, and finally output the HTML form for the survey item. The name of the problem in the form is "CHOICE" plus the question number. When this form is submitted, its action loads pollmaker.asp (the function saveresponses () extracts the voting results from the choice form element, and then updates the database, the code slightly). Other hidden variables in the form are used to pass Pollname, Optype, LinkText, Linkurl to pollmaker.asp:


<%
' Read the survey project definition from the S_ table and the A_ table
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Poll"
SQLCommand = "Select" & sname & ". ID," & _
"Itype, Noopinion, Stem, Alabel, Answer from" & Sname & "Left JOIN" & _
Aname & "On" & Sname & ". id =" & aname & ". ID ORDER By" & _
Sname & ". ID, Alabel"
Set objRS = objConn.Execute (SQLCommand)
' Output various issues to the survey form
Do as Not objrs.eof
Response.Write ("< tr>< td>" & objRS ("ID") & ".< TD bgcolor=" "#ffff00" ">" & _
objRS ("Stem"))
Response.Write ("< tr>< td>< td>")
Cknoopinion = IIf (objRS ("noopinion") = "Y", "", "Checked")
Nomove = False
' Except for ' Allow check ', all other types of questions need to be checked for permission not to answer questions
Ansname = "" CHOICE "& objRS (" ID ") &" ""
Select case objRS ("Itype")
Case "1" ' Yes/No
If cknoopinion = "" Then
Response.Write ("< INPUT type=radio name=" & Ansname & _
"Value=" "" Checked> No Answer ")
End If
Response.Write ("< INPUT type=radio name=" & Ansname & _
"Value=" "A" "" & Cknoopinion & "> Yes")
Response.Write ("< INPUT type=radio name=" & Ansname & _
"Value=" "B" "> No")
Case "2" ' approval degree
... Slightly...
Case "3" ' Semantic distinction
... Slightly...
Case "4" multiple options
... Slightly...
Case "5" ' Allow check
... Slightly...
End Select
If Nomove Then
Nomove = False
ElseIf Not objrs.eof Then
Objrs.movenext
End If
Loop
%>


Pollresult.asp uses the same SQL commands as pollwrite.asp to extract the Recordset from the A_ table (answer) and S_ table (problem), then reads the user answer from the corresponding R_ table, and uses a two-dimensional array to counts the statistical voting results. The default results analysis does not contain "no answers," If you want to include, you need to give the form variable shownoop and specify that its value is true, see Figure 4, the URL that shows the voting result.


<%
' Globals
Dim Pollname
Dim Counts () ' An array of statistics answered by the user
Dim nresponses
Dim N ' user answer quantity, may not contain ' no answer ' option
Dim objconn
Dim objRS

nresponses = 0

Call Main

Sub Main
Dim Likert
Dim I
Likert = Array ("strongly opposed", "against", "indeterminate", "agreed", "fully agreed")
Pollname = Request ("Pollname")
Shownoop = IIf (UCase (Request ("shownoop") = "true", TRUE, False)
' Read the survey project definition from the A_ table and the S_ table
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Poll"
sname = "[S_" & Pollname & "]"
Aname = "[A_" & Pollname & "]"

If Count () = False Then
Response.Write ("< br> this survey project did not vote")
Exit Sub
End If
SQLCommand = "Select" & sname & ". ID," & _
"Itype, Noopinion, Stem, Alabel, Answer from" & Sname & _
' Left JOIN ' & Aname & ' on ' & Sname & '. ID = "& Aname & _
". ID ORDER By" & Sname & ". ID, Alabel"
Set objRS = objConn.Execute (SQLCommand)

Response.Write ("< table>")
... Output the form title, slightly ...
Response.Write ("< tr>< TD colspan=5>")
Itemix = 0 ' question number
Do as Not objrs.eof
Itype = objRS ("Itype")
Nomove = False
N = IIf (Shownoop Or itype=5, nresponses, nresponses-counts (itemix, 0))
n = IIf (n=0, 1, N)
Response.Write ("< tr>< TH align=right>" & objRS ("ID") & _
".< TH align=left colspan=4 bgcolor=" "#ffff00" ">" & objRS ("Stem"))
Response.wr



Related Article

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.