1. vote.asp
<%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%Response.Buffer = True%>
<!-- #INCLUDE FILE="adovbs.inc" -->
<%
'*** Remember to create those variables before trying to use them.
Dim objConn
Dim objRec3
Dim strConnect
Dim varTopic, varTopicID, varSelectionNum, varSelected
Dim i, varTotal, varThis, varThisTitle, varAlreadyVote
strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("vote.mdb") & ";DefaultDir=" & Server.MapPath(".") & ";DriverId=25;FILE=MS Access;MaxBufferSize=512;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;;User Id=admin;"
Set objConn = Server.CreateObject ("ADODB.Connection") '*** Create an ADO database connection object.
Set objRec3 = Server.CreateObject ("ADODB.Recordset") '** Create an ADO RecordSet object.
objConn.Open strConnect '*** Open the connection to the database
objRec3.Open "vote", objConn, adOpenForwardOnly, adLockPessimistic, adUseServer '*** Open the recordset
varTopic = Request.Form("topic")
varTopicID = Request.Form("topicID")
if varTopicID="" then
varTopicID = Request.QueryString("topicID")
end if
varSelectionNum = Request.Form("selectionNum")
varSelected = Request.Form("selected")
objRec3.Filter = 0
objRec3.Filter = "topicID=" & varTopicID 'only number can be filter?
If NOT objRec3.EOF then
if Request.Form("selected") = "" then
else
varAlreadyVote="alreadyVote" & "_" & varTopicID
if Session(varAlreadyVote)<>"true" then
objRec3("selection" & varSelected & "_count") = objRec3("selection" & varSelected & "_count") +1
objRec3.Update
Session(varAlreadyVote)="true"
end if
end if
varTotal=0
for i=0 to objRec3("selectionNum")-1
varTotal=varTotal+ objRec3("selection" & i & "_count")
next
%>
<p align=left> <% =varTopic %> </p>
<p align=center>
<table width=480 border=0 cellspacing=0 cellpadding=0 bgcolor=#000000>
<caption align=left><font size=2>共有 <font color=red><% =varTotal %></font>人参加</font></caption>
<tr><td>
<table width=480 border=0 cellspacing=1 cellpadding=3>
<tr bgcolor=#dcdcdc align=center valign=center>
<th width=120><font size=2>选项</font></td>
<th width=300><font size=2>比 例</font></td>
<th width=60><font size=2>人数</font></td>
</tr>
<%
for i=0 to objRec3("selectionNum")-1
varThisTitle=objRec3("selection" & i & "_title")
varThis=objRec3("selection" & i & "_count")
%>
<tr bgcolor=#ffffff valign=center>
<td width=120 align=center><font size=2 color=#ff0000><% =varThisTitle %></font></td>
<td width=300 align=left><img src="color.gif" width=<% =varThis*100/varTotal %> height=12 border=0><font size=2 color=#ff0000>
<% = left(varThis*100/varTotal, 5) %>%
</font>
</td>
<td width=60 align=center><font size=2 color=#ff0000><% =varThis %></font></td>
</tr>
<%
next
%>
</table>
</td></tr>
</table></p>
<%
else 'no this topic yet
objRec3.AddNew
objRec3("topicID") = varTopicID
objRec3("topic") = varTopic
objRec3("selectionNum") = varSelectionNum
for i=0 to varSelectionNum
objRec3("selection" & i & "_title") = Request.Form("selection" & i & "_title")
next
objRec3.Update
response.write "added"
End If
objRec3.Close
objConn.Close
Set objRec3 = Nothing
Set objConn = Nothing
%>
2. vote.htm
<HTML>
<HEAD>
<script language="JavaScript">
function newswindow(url)
{ContentWindow=window.open(url,"_blank","toolbar=no,width=640,height=400;,directories=no,status=yes,scrollbars=yes,resize=yes,menubar=yes")
}
</script>
</HEAD>
<BODY>
您认为"你说我说"栏目
<form method="post" action="vote.asp" onSubmit="windowOpener('')" target="new">
<tr>
<td width=80>
<input type="radio" name="selected" value="0" style="background-color:rgb(255,205,96)">比较混乱<br>
<input type="radio" name="selected" value="1" style="background-color:rgb(255,205,96)">马马虎虎<br>
<input type="radio" name="selected" value="2" style="background-color:rgb(255,205,96)">秩序井然
</td>
<td width=55>
<input type=hidden name=topicID value=1>
<input type=hidden name=topic value=您认为'你说我说'栏目>
<input type=hidden name=selectionNum value=3>
<input type=hidden name=selection0_title value=比较混乱>
<input type=hidden name=selection1_title value=马马虎虎>
<input type=hidden name=selection2_title value=秩序井然>
<input type="button" value="查看" style="background-color:rgb(255,205,96)" onClick=newswindow("vote.asp?topicID=1") target=new>
<input type=submit value="提交" style="background-color:rgb(255,205,96)">
</td>
</tr>
</form>
</BODY>
</HTML>
3. vote.mdb
a Access database file, there is a table named "vote"
fields:
topicID topic selectionNum selection0_title selection0_count ...
本文地址:http://com.8s8s.com/it/it9523.htm