<% poll_name="codeave_poll" 定义正进行选票的名称 accessdb="cookiepoll"
安排变量数据库到包含选票结果的数据库名称
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
taken= (request.cookies (poll_name)("u_choice"))
安排一个变量来看用户是否首先选票
u_choice=request.querystring("u_choice")
select case u_choice
检查看看用户是否进行了有效的选择
case "1","2","3","4"
if taken = "" then
写出投票名称和cookie最近的选择
response.cookies (poll_name)("u_choice") = u_choice
让cookie在7天之内截止
response.cookies (poll_name).expires = DATE + 7
添加一个到用户选择的计算中去
sql = "insert into poll (choice" & u_choice &") "
sql = sql & "values ("& 1 &")"
rs.Open sql, cn
标志指示已输入表决
just_voted="Yes"
end if
%>
<% case else
忽略用户地址栏输入的错误请求
end select
%>
<html>
<title>www.ttasp.net(cookie Poll)</title>
<body bgcolor="#FFFFFF">
<center>
A Question with four possible choices...<br>
<%
检查看用户是否预先选了票或者是否在当前的复述里面
if (taken <> "") or (just_voted= "Yes") then
抓住来自数据库的所有的选票结果
sql= "select distinctrow sum(choice1) as sum_choice1, "
sql= sql & "sum(choice2) AS sum_choice2, sum(choice3) AS sum_choice3, "
sql= sql & "sum(choice4) AS sum_choice4, count(*) AS total_votes "
sql= sql & "from poll;"
rs.Open sql, cn
total1=rs ("sum_choice1")
total2=rs ("sum_choice2")
total3=rs ("sum_choice3")
total4=rs ("sum_choice4")
count=rs ("total_votes")
%>
Choice 1: <%= formatnumber((total1/count)*100,1) %>%
Choice 2: <%= formatnumber((total2/count)*100,1) %>%
Choice 3: <%= formatnumber((total3/count)*100,1) %>%
Choice 4: <%= formatnumber((total4/count)*100,1) %>%
<br>
Total Votes: <%= formatnumber(count,0,0) %><br>
<%
'If this is the users first time here or if they have not
'voted on a previous visit display the question and hyperlinked choices
如果这是用户在这里的首次时间或者如果他们没有在预先访问的时候选票显示问题和超链接选项
else
%>
<a href="<% request.servervariables("script_name") %>?u_choice=1">Choice 1</a>
<a href="<% request.servervariables("script_name") %>?u_choice=2">Choice 2</a>
<a href="<% request.servervariables("script_name") %>?u_choice=3">Choice 3</a>
<a href="<% request.servervariables("script_name") %>?u_choice=4">Choice 4</a>
<% end if %>
</html>
热门信息
阅读 (198)
1 独特的随机字母阅读 (171)
2 检查和设置IIS服务器正确的权限阅读 (163)
3 asp网站伪静态化URL Rewrite中的httpd.ini伪静态化规则编写方法阅读 (161)
4 ASP-对象阅读 (160)
5 随机图像