您的位置:首页精文荟萃软件资讯 → 如何使用ASP在自己的网站建立投票机制(一)

如何使用ASP在自己的网站建立投票机制(一)

时间:2004/10/7 19:04:00来源:本站整理作者:蓝点我要评论(0)


            
             
              
             
            

               
               

            



            一个很不错的建立自己的投票系统的ASP程序大家仔细读读,只要能够理解中间的关键技术,就能够在自己的网站上建立自己的投票站了。文件整理得很仓促,希望大家谅解。
版权所有:
ASP Polls
version 1.0
Tipped Cow Development and Adrenalin Labs
结构简单介绍:
ACCESS数据库设计结构:
poll表主要字段名称:PollName,PollCreator,PollQuestion,Password,Choice1,Choice2
Choice3,Choice4,Choice5,ID(自动编号),GetName
pollresults表字段:PollID,PollAnswer,Name
1.文件db.inc
<%
Application("ASP_Poll") = "ASP_Poll"
cnString = "DRIVER={Microsoft Access Driver (*.mdb)}; "
cnString = cnString & "DBQ=" & Server.MapPath("Events.mdb")
Application("ASPPollDSN") = cnString
%>
1.文件creat_poll1.asp
<% Title="Poll Generator" %>

<%=Title%>



Another joint product from Tipped Cow Development and Adrenalin Labs






<%
Response.Write ""
If Request("errormessage") <> "" Then
Response.Write "Error! " & Request("errormessage")
Else
Response.Write "Please complete the form below to begin creating your own poll."
End If
%>


















Enter Your Name as the Poll Creator
Poll Creator:
" size=20 class="input">











Create a Password For Your Poll So That You Can Modify It At A
Later Time
Poll Admin Password:
" size=10 maxlength=10 maxsize=10 class=input>











Give Your Poll a Unique Name
Poll Name:
" size=20 class=input>









Do you want to have the user enter their name?
Require user to enter their name:
Yes

No













Select Poll Type
What type of poll question
do you wish to create?

Yes/No

Multiple Choice












3.文件connect.asp
<%
id = Request("id")
If id = "" Then
id = 0
End If
num = Request("choice")

If num <> "" Then

Set conn = Server.CreateObject("ADODB.Connection")
dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
conn.open dsnpath
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open "PollResults", conn, 3, 3
rs.AddNew
rs("PollID") = Cint(id)
rs("Name") = Request("Name")
rs("PollAnswer") = Cint(num)
rs.Update
rs.Close
set rs = Nothing
conn.Close
set conn = Nothing
End If

If Request("return_page") <> Empty Then
Response.Cookies("PollID") = id
Response.Redirect Request("return_page")
End If
%>





<% If num <> "" Then %>







Your selection has been recorded.


<% End If %>



<%

Set conn = Server.CreateObject("ADODB.Connection")
sql = "select * from Poll where ID = " & Cint(id)
dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
conn.open dsnpath
Set rs = Conn.Execute(sql)
If rs.EOF = False Then
%>


<%
Dim Choices(6)
Dim Responses(6)
For I=1 To 5
choice = rs("Choice" & I)
Choices(I) = choice
If choice <> "" Then
Set conn2 = Server.CreateObject("ADODB.Connection")
sql = "select COUNT(PollAnswer) from PollResults where PollID = " & Cint(id) & " AND PollAnswer=" & I
dsnpath = "DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; "
dsnpath = dsnpath & "DBQ=" & Server.MapPath("Events.mdb")
conn2.open dsnpath
Set rs2 = Conn.Execute(sql)
If rs2.EOF = False Then
Response.Write ""
Responses(I) = rs2(0)
Response.Write ""
Response.Write ""
End If
rs2.Close
conn2.Close
End If
Next
End If
%>


<%=rs("PollQuestion")%>
"
Response.Write choice
Response.Write "
" & rs2(0) & "









<%
Total = 0
For I=1 To 5
responseCount = Responses(I)
If responseCount <> "" Then
Total = Total + Cint(responseCount)
End If
Next
For I=1 To 5
choice = Choices(I)
responseCount = Responses(I)
If choice <> "" Then
Response.Write ""
Response.Write ""
Response.Write ""
End If
Next

Function ConvertToPix(sz)
If sz = 0 Then
ConvertToPix = 0
Else
ConvertToPix = Cint(400/Total * sz)
End If
End Function

Function ConvertToPercent(sz)
If sz = 0 Then
ConvertToPercent = "0%"
Else
ConvertToPercent = FormatPercent(sz/Total, 2)
End If
End Function

%>


Polls Results
"
Response.Write choice
Response.Write "
" & ConvertToPercent(responseCount) & "



<% If num = "" Then %>







Add Your Vote


<% End If %>






Back






相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本