ASP+VML+DB implementation of the voting statistics project

Source: Internet
Author: User
Tags date count execution include mdb database modify reset trim
A few months ago I saw a netizen Lshdic wrote an article using the JS+VML "use VML to produce solid columnar ballot statistics Map of the complete procedure."
I think this method is very good, can not use the picture to generate a statistical map, now let us use ASP to implement this program.

Preparation: Use Access to create an MDB database, named Vote.mdb, and create the following two tables in the database:



Then we build a file that connects to the database based on the conventions developed by ASP conn.asp
<%
' Conn.asp
Set conn=server.createobject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Server.MapPath ("Vote.mdb")
%>

display a list of voting items, because we're going to make a multiple-item voting system vote_list.asp
<!--#include file= "conn.asp"-->
<title> List of voting items </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ""
<link href= ". /images/main.css "rel=" stylesheet "type=" Text/css "

<%
Set Rs=conn.execute ("SELECT * from Votetitle ORDER by Voteid Desc")
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "0" bgcolor= "#ffffff" bordercolor= "# 000000 "Width=100%>
  <tr>
    <td bgcolor=" #EFEFEF "> All voting list </td>
  </TR>
  <%do while not rs.eof%>
  <tr>
    <td> Item No: <font color= "#FF0000" ><%=rs ("Voteid")%>  </font><a "href=" (" Voteid ")%>" target= "_blank" ><%=rs ("Votetitle")%>
      </a> (<%= RS ("Time")%>) </td>
  </tr>
  <%rs.movenext 
loop 
Rs.close
Set Rs=nothing%>
</table>
</body>

Voting Display page vote_show.asp
<%if request ("Voteid") = "" Then
The Response.Write parameter is not specified. "
Response. End ()
End If%>
<!--#include file= "conn.asp"-->
<title> View Results </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<STYLE>
TD{FONT-SIZE:12PX}
BODY{FONT-SIZE:12PX}
V\:* {behavior:url (#default #vml);}//Here declares V as a VML public variable
</STYLE>
<link href= ". /images/main.css "rel=" stylesheet "type=" Text/css ">
<%
Dim Voteid
Voteid=request ("Voteid")
Set Rs=conn.execute ("Select count from Vote,votetitle where votetitle.voteid=" &voteid& "and vote.voteid= Votetitle.voteid ORDER by id ")
Iii=0
Do as not rs.eof
Ii=ii+1
If Ii=1 Then
Ceocio=trim (RS ("Count"))
Ceocio1=trim ("array1[" &iii& "]")
Else
Ceocio=trim (ceocio& "," &rs ("Count"))
Ceocio1=trim (ceocio1& "+array1[" &iii& "]")
End If
Iii=iii+1
Rs.movenext
Loop
Rs.close
Set rs=nothing
' Response.Write II
' Response.Write ceocio1
%>
<script>
Array1=new Array (<%=ceocio%>)//different number of votes
Allstr=<%=ceocio1%>
Alert (ALLSTR)
ALLSTR=ARRAY1[0]+ARRAY1[1]+ARRAY1[2]+ARRAY1[3]+ARRAY1[4]+ARRAY1[5]//Get Total
For (i=0;i<=<%= (ii-1)%>;i++) {
Mathstr=math.round (100/(Allstr/array1[i]))//Percent, 100/(Sum/single)
document.write ("<v:rect fillcolor= ' lime ' style= ' width:20;color:navy;height:" +500*<%= (ii-1)%>/(1000/ MATHSTR) + "' ><br>%" +mathstr+ "<br>" +array1[i]+ "person <v:extrusion backdepth= ' 15pt ' on= ' true '/>< /v:rect> ")
}
</script>
<%
Voteid=request ("Voteid")
Set Rs=conn.execute ("SELECT * from Vote,votetitle where votetitle.voteid=" &voteid& "and vote.voteid= Votetitle.voteid ORDER by id ")
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "2" bgcolor= "#ffffff" bordercolor= "# 000000 "width=100%>
<tr>
&LT;TD bgcolor= "#EFEFEF" > About: <font color= "#FF0000" ><%=rs ("Votetitle")%></font> findings: &LT;BR >
<b><font color= "#FF0000" ><%=rs ("Total")%></font></b> participants in the survey <br>
(<%=rs ("Time")%> to <%=date%>) </td>
</tr>
<%do While not rs.eof
Dim i
I=i+1%>
<tr>
<td> options <%=i%>:<%=rs ("title")%> <font color= "#FF0000" ><%=rs ("Count")%> person </font> </td>
</tr>
<%rs.movenext
Loop
Rs.close
Set rs=nothing%>
<tr>
<td> </td>
</tr>
</table>
<br>
<a href= "vote_list.asp" > View past polls </a> <br>
<a href= "Vote.asp?voteid=<%=request (" Voteid ")%>" > Vote this project </a>
</body>

Vote.asp
<!--#include file= "conn.asp"-->
<%if request ("Voteid") = "" Then
Set Rs=conn.execute ("Select top 1 Voteid to Votetitle ORDER by Voteid Desc")
Voteid=rs ("Voteid")
Rs.close
Set rs=nothing
Else
Voteid=request ("Voteid")
End If%>
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link href= "Style.css" rel= "stylesheet" type= "Text/css" >

<body>
<%
If Request ("action") = "vote" Then
"Plus", "&request (" Voteid ")", "in order not to make the poll with ID 1 and the vote of ID 11 mix ya
If InStr (Request.Cookies ("vote"), "," &request ("Voteid") & ",") =0 Then
Else
Response.Write "You've already voted."
Response.End
End If
sql= "Update [vote] set count=count+1 where id=" &request ("Votevalue")
Conn.execute (SQL)
sql= "Update [Votetitle] set total=total+1 where voteid=" &request ("Voteid")
Conn.execute (SQL)
' Write cookie Validity
Response.Cookies ("vote"). Expires=date+1
' All the options that have been voted are recorded in cookies, separated by a number.
Response.Cookies ("vote") = "," &request.cookies ("vote") & "," &request ("Voteid") & ","
Voteid=request ("Voteid")
' Turn to basic
Response.Redirect "Vote_show.asp?voteid=" &voteid
End If
%>
<%
' Dim Voteid
' Voteid=request ("Voteid")
Set Rs=conn.execute ("SELECT * from Vote,votetitle where votetitle.voteid=" &voteid& "and vote.voteid= Votetitle.voteid ORDER by id ")
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "0" bgcolor= "#ffffff" bordercolor= "# C0C0C0 "width=100%>
<tr>
&LT;TD colspan= "2" bgcolor= "#EFEFEF" > Survey: <%=rs ("Votetitle")%> (<%=rs ("Time")%>) </td>
</tr><form name= "Form1" method= "Post" action= "vote.asp?action=vote&voteid=<%=voteid%>" >
<%do While not rs.eof
Dim i
I=i+1%>
<tr>
&LT;TD colspan= "2" >
<input type= "Radio" name= "Votevalue" value= <%=rs ("id")%> "<%if i=1 then%>checked<%end if%>>
<%=rs ("title")%>
</td>
</tr>
<%rs.movenext
Loop
Rs.close
Set rs=nothing%>
<tr>
&LT;TD colspan= "2" >
<%if InStr (Request.Cookies ("vote"), "," &voteid& ",") =0 then%>
<input type= "Submit" name= "Submit" value= "Vote" ></form>
<%else%>
<font color= "#FF0000" > You've already voted. </font>
<%end if%></td>
</tr>
</table>
<br>
<a href= "vote_list.asp" > View past polls </a> <br>
<a href= "vote_show.asp?voteid=<%=voteid%>" > View the results of this poll </a>
</body>

Admin page admin_vote_list.asp
<!--#include file= "conn.asp"-->
<% ' Add admin privileges here, here for the convenience of everyone, I have not verified the direct permission to enter the%>
<title> Voting Items List </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link href= "Style.css" rel= "stylesheet" type= "Text/css" >

<body>
<%
' Delete module
Dim action
Action=request ("Action")
If action= "Del" Then
Dim STRSQL1,STRSQL2
Strsql1= "Delete from vote where voteid=" &request ("Voteid")
Conn. Execute StrSQL1
strsql2= "Delete from Votetitle where voteid=" &request ("Voteid")
Conn. Execute StrSQL2
Response. Redirect "?"
End If
' Modify module
'/////////////////////
' Modify the form
If action= "Add" then
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "0" bgcolor= "#ffffff" bordercolor= "# C0C0C0 "width=100%>
<tr>
&LT;TD bgcolor= "#EFEFEF" ><center>
Add a new poll </center></td>
</tr>
<tr>
<td> Please enter the number of options required for this poll. </td>
</tr>
<tr>
<td><form name= "Form1" method= "Post" action= "ACTION=ADD1" >
<select name= "num" >
<%for i1=2 to 10%>
<option value= "<%=i1%>" ><%=i1%></option>
<%next%>
</select>
<input type= "Submit" name= "submit" value= "Submit" >
</form></td>
</tr>
</table>
<%
End If
If action= "Add1" Then
Num=request ("num")
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "0" bgcolor= "#ffffff" bordercolor= "# C0C0C0 "width=100%>
<tr>
&LT;TD bgcolor= "#EFEFEF" ><center>
Add a new poll </center></td>
</tr>
<tr>
<td> Please enter the detailed information required for this poll. </td>
</tr>
<tr>
<td><form name= "Form2" method= "post" action= "ACTION=ADD2" >
Voting name
<input type= "text" name= "Votetitle" >
<br>
<%for I2=1 to Num%>
Option <%=i2%><input type= "text" name= "<%=i2%>" ><br>
<%next%>
<input type= "hidden" name= "num" value= "<%=request (" num ")%>" >
<input type= "Submit" Name= "Submit2" value= "Submit" >
<input type= "reset" name= "SUBMIT3" value= "reset" >
</form></td>
</tr>
</table>

<%end if
If action= "Add2" Then
Set rs=server.createobject ("ADODB. Recordset ")
Sql= "SELECT * from Votetitle"
Rs. Open sql,conn,1,3
Rs. Addnew
RS ("Votetitle") =request ("Votetitle")
RS ("Time") =date ()
Rs. Update
Rs. Close
Set Rs=conn.execute ("Select top 1 Voteid to Votetitle ORDER by Voteid Desc")
Voteid=rs ("Voteid")
Rs.close
Set rs=nothing
'//////////////
'/////////////cycle
Num=request ("num")
For I3=1 to Num
Set rs=server.createobject ("ADODB. Recordset ")
Sql= "SELECT * from vote"
Rs. Open sql,conn,1,3
Rs. Addnew
RS ("title") =request (i3)
RS ("Voteid") =voteid
Rs. Update
Rs. Close
Next
'////////////cycle ends
Set rs=nothing
Response. Write "<a href=admin_vote_list.asp> successfully added, please return to </a>"
End If
' Modify the form end
'////////////////////
' Modify the execution code
' Modify execution code end
%>

<%if action= "" Then
Set Rs=conn.execute ("SELECT * from Votetitle ORDER by Voteid Desc")
%>
<table border=1 cellspacing= "0" style= "border-collapse:collapse" cellpadding= "0" bgcolor= "#ffffff" bordercolor= "# C0C0C0 "width=100%>
<tr>
&LT;TD colspan= "2" bgcolor= "#EFEFEF" > All voting lists </td>
</tr>
<%do While not rs.eof%>
<tr>
&LT;TD width= "44%" > No.: <font color= "#FF0000" ><%=rs ("Voteid")%> </font><a "href="? Voteid=<%=rs ("Voteid")%> "target=" _blank "><%=rs (" Votetitle ")%>
</a> (<%=rs ("Time")%>) </td>
&LT;TD width= "50%" > "<a href=" Action=del&voteid=<%=rs ("Voteid")%> "> Delete </a>" </td>
</tr>
<%rs.movenext
Loop
Rs.close
Set rs=nothing%>
<tr>
&LT;TD colspan= "2" > "<a href=" "Action=add" > Add a new poll item </a> "</td>
</tr>
</table>
</body>
<%end if%>

The final display effect is as follows:




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.