欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

batman 翻译整理

一个很不错的建立自己的投票系统的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" %>

<head> <link rel="stylesheet" type="text/css" href="style.css">

<title><%=title%></title>

</head>

<body>

<div align="left"><img src="asp_poll.gif" width="231" height="90"><br>another joint product from <a href="http://www.ncws.com/tippycow">tipped cow development</a> and <a href="http://dstoflet.calweb.com">adrenalin labs</a>

<br><br>

</div>

<center>

<%

response.write "<font face=arial>"

if request("errormessage") <> "" then

response.write "<b>error! </b>" & request("errormessage")

else

response.write "please complete the form below to begin creating your own poll."

end if

%>

<br><br>

<table border=2 cellspacing=0 cellpadding=0><tr><td>

<form method="post" action="create_poll2.asp">

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>

<td colspan=2 bgcolor=#000000 align=center class="bold2">

enter your name as the poll creator

</td>

</tr><tr>

<td bgcolor=#ffffff width=25% class="bold">poll creator:</td>

<td bgcolor=#ffffff>

<input type="text" name="creator" value="<%=request("creator")%>" size=20 class="input">

</td>

</tr>

</table>

</td></tr>

<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>

<td colspan=2 bgcolor=#000000 align=center class="bold2">

create a password for your poll so that you can modify it at a

later time

</td>

</tr><tr>

<td bgcolor=#ffffff width=25% class="bold">poll admin password:</td>

<td bgcolor=#ffffff>

<input type="password" name="password" value="<%=request("password")%>" size=10 maxlength=10 maxsize=10 class=input>

</td>

</tr>

</table>

</td></tr>

<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>

<td colspan=2 bgcolor=#000000 align=center class="bold2">

give your poll a unique name

</td>

</tr><tr>

<td bgcolor=#ffffff width=25% class="bold">poll name:</td>

<td bgcolor=#ffffff>

<input type="text" name="name" value="<%=request("name")%>" size=20 class=input>

</td>

</tr>

</table>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>

<td colspan=2 bgcolor=#000000 align=center class="bold2">

do you want to have the user enter their name?

</td>

</tr><tr>

<td bgcolor=#ffffff width=25% class="bold">require user to enter their name:</td>

<td bgcolor=#ffffff class="bold">

yes<input type="radio" name="getname" value="1"><br>

no <input type="radio" name="getname" value="0" checked>

</td>

</tr>

</table>

</td></tr>

<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>

<td colspan=3 bgcolor=#000000 align=center class="bold2">

select poll type

</td>

</tr><tr>

<td colspan=2 bgcolor=#ffffff class="bold">what type of poll question

do you wish to create?</td>

<td bgcolor=#ffffff class="bold">

<input type="radio" name="polltype" value="yes_no">yes/no<br>

<input type="radio" name="polltype" value="multiple_choice">multiple choice<br>

</td>

</tr>

</table>

</td></tr></table>

<table width=500><tr>

<td colspan=3 align=right>

<input type="submit" value=" next " class="inline">

</td></tr>

</table>

</center>

</body>

</html>

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

%>

<html>

<body bgcolor="#4f4f4f" text="#c0c0c0" link=#f5fcdc vlink=#f5fcdc>

<center>

<% if num <> "" then %>

<br><br>

<table border=0 cellspacing=0 cellpadding=0><tr>

<td colspan=3 align=center><font face="verdana">

your selection has been recorded.

</td></tr>

</table>

<% end if %>

<br><br>

<%

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

%>

<table border=1 cellspacing=0 cellpadding=5 width=500 bordercolor=#2f2f4f><tr>

<td colspan=3 bgcolor=#2f2f4f align=center><font face="verdana" color=#f5fcdc>

<%=rs("pollquestion")%>

</td></tr>

<%

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 "<tr><td colspan=2 bgcolor=#4f4f4f align=center width=400><font face=verdana color=#f5fcdc>"

response.write choice

response.write "</td>"

responses(i) = rs2(0)

response.write "<td colspan=1 bgcolor=#4f4f4f align=right><font face=verdana color=#f5fcdc><b>" & rs2(0) & "</b></td>"

response.write "</tr>"

end if

rs2.close

conn2.close

end if

next

end if

%>

</table>

<br><br>

<table >

<td colspan=3 align=center><font face="arial">

<font face="ms sans serif"><b> polls results</b></font>

</td></tr>

<%

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 "<tr><td colspan=1 align=left><font face=arial>"

response.write choice

response.write "</td>"

response.write "<td colspan=2 width=400><table border=1 cellspacing=0><tr><td bgcolor=blue align=center width=" & converttopix(responsecount) & "><font face=ms sans serif color=white><b>" & converttopercent(responsecount) & "</td></tr></table></td>"

response.write "</tr>"

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

%>

</table>

<% if num = "" then %>

<br><br>

<table border=0 cellspacing=0 cellpadding=0><tr>

<td colspan=3 align=center><font face="verdana">

<a href="default.asp?id=<%=id%>">add your vote</a>

</td></tr>

</table>

<% end if %>

<br><br>

<table width=100%><tr><td align=right>

<table border=1 cellpadding=5 cellspacing=0 bordercolor=#f5fcdc><tr><td bgcolor=#2f2f4f>

<font face=verdana size=+1><a href=javascript:history.back()>back</a>

</td></tr></table>

</td></tr></table>

</center>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何使用ASP在自己的网站建立投票机制(一)
分享到: 更多 (0)

相关推荐

  • 暂无文章