A few months ago, I saw an article written by a netizen lshdic using JS+VML "A complete program to create a three-dimensional columnar voting chart using Vml".
I think this method is very good. It can generate statistical charts without using pictures. Now let us implement this program using ASP.
Preparation: Use ACCESS to create an MDB database named vote.mdb, and create the following two tables in the database:
Then we create the file conn.asp that connects to the database according to the convention of ASP development.
<%
'conn.asp
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& Server.MapPath("vote.mdb")
%>
Display the list of voting projects, because what we want to make is a multi-project voting system vote_list.asp
<!--#include file="conn.asp"-->
<html>
<head>
<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">
</head>
<%
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 lists</td>
</tr>
<%do while not rs.eof%>
<tr>
<td>Number:<font color="#FF0000"><%=rs("voteid")%> </font><a href="vote.asp?voteid=<%=rs("voteid" )%>" target="_blank"><%=rs("votetitle")%>
</a>(<%=rs("time")%>)</td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing%>
</table>
</body>
</html>
Vote display page vote_show.asp
<%if request("voteid")="" then
response.write "The parameter was not specified."
response.End()
end if%>
<!--#include file="conn.asp"-->
<html>
<head>
<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);} //v is declared here as a VML public variable
</STYLE>
<link href="../images/main.css" rel="stylesheet" type="text/css">
</head>
<%
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 while 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 voting numbers
allstr=<%=ceocio1%>
//alert(allstr)
//allstr=array1[0]+array1[1]+array1[2]+array1[3]+array1[4]+array1[5] //Get the total number
for(i=0;i<=<%=(ii-1)%>;i++){
mathstr=Math.round(100/(allstr/array1[i])) //Find the percentage, 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]+"人<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>
<td bgcolor="#EFEFEF">Finding results about:<font color="#FF0000"><%=rs("votetitle")%></font>:<br>
A total of<b><font color="#FF0000"><%=rs("total")%></font></b> participated in the survey<br>
(<%=rs("time")%>to<%=date%>)</td>
</tr>
<%do while not rs.eof
dimi
i=i+1%>
<tr>
<td>Option<%=i%>:<%=rs("title")%> <font color="#FF0000"><%=rs("count")%>People< /font></td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing%>
<tr>
<td> </td>
</tr>
</table>
<br>
<a href="vote_list.asp">View past votes</a> <br>
<a href="vote.asp?voteid=<%=request("voteid")%>">Vote for this project</a>
</body>
</html>
vote.asp
<!--#include file="conn.asp"-->
<%if request("voteid")="" then
set rs=conn.execute("select top 1 voteid from votetitle order by voteid desc")
voteid=rs("voteid")
rs.close
set rs=nothing
else
voteid=request("voteid")
end if%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
if request("action")="vote" then
'Add ","&request("voteid")","in order not to confuse the vote with id 1 and the vote with id 11
if instr(request.cookies("vote"),","&request("voteid")&",")=0 then
else
response.write "You have 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 period
Response.Cookies("vote").Expires=Date+1
'Record all voted options in cookies, separated by ','.
Response.Cookies("vote")=","&Request.Cookies("vote")&","&Request("voteid")&","
voteid=request("voteid")
'Go to basics
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>
<td colspan="2" bgcolor="#EFEFEF">Investigation: <%=rs("votetitle")%>(<%=rs("time")%>)</td>
</tr><form name="form1" method="post" action="vote.asp?action=vote&voteid=<%=voteid%>">
<%do while not rs.eof
dimi
i=i+1%>
<tr>
<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>
<td colspan="2">
<%if instr(request.cookies("vote"),","&voteid&",")=0 then%>
<input type="submit" name="Submit" value="Vote"></form>
<%else%>
<font color="#FF0000">You have already voted</font>
<%end if%></td>
</tr>
</table>
<br>
<a href="vote_list.asp">View past votes</a> <br>
<a href="vote_show.asp?voteid=<%=voteid%>">View the results of this vote</a>
</body>
</html>
Backend management page admin_vote_list.asp
<!--#include file="conn.asp"-->
<%'Add administrator rights here. For everyone's convenience, I will directly allow entry without verification%>
<html>
<head>
<title>List of voting items</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
'Delete module
dim action
action=request("action")
if action="del" then
DimStrSQL1,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 form
if action="add" then
%>
<table border=1 cellspacing="0" style="border-collapse: collapse" cellpadding="0" bgcolor="#ffffff" bordercolor="#C0C0C0" width=100%>
<tr>
<td bgcolor="#EFEFEF"><center>
Add 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>
<td bgcolor="#EFEFEF"><center>
Add new poll</center></td>
</tr>
<tr>
<td>Please enter the details 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%>
Options<%=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 from 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
'////////////End of loop
Set rs=Nothing
response.Write "<a href=admin_vote_list.asp>Added successfully, please return</a>"
end if
'End of modification form
'//////////////////////
'Modify the execution code
'End of modifying the execution code
%>
<%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>
<td colspan="2" bgcolor="#EFEFEF">All voting lists</td>
</tr>
<%do while not rs.eof%>
<tr>
<td width="44%">Number: <font color="#FF0000"><%=rs("voteid")%> </font><a href="vote.asp?voteid=<% =rs("voteid")%>" target="_blank"><%=rs("votetitle")%>
</a>(<%=rs("time")%>)</td>
<td width="50%">【<a href="?action=del&voteid=<%=rs("voteid")%>">Delete</a>】</td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing%>
<tr>
<td colspan="2">[<a href="?action=add">Add a new poll</a>]</td>
</tr>
</table>
</body>
</html>
<%end if%>
The final display effect is as follows: