创建一个Web投票系统

饺子灬爱吃肉

饺子灬爱吃肉

2016-01-29 17:33

创建一个Web投票系统,创建一个Web投票系统
  下面zip文件:http://www.content.aspdir.co.uk/files/Article-11.zip

During this article you will learn how to construct your own web poll using ASP. The article presumes you
already understand basic database interaction.



The following samples of code allow a user to select one of four options to a question. The user's vote is
then recorded in a database and the user is taken to a page where the results for each option can be
viewed in statistical, numerical and graphical form. Not bad, huh?

The whole application is based on the database itself, so when the values within the database are altered,
the application automatically changes. The database design itself, is not included within this article so
make sure to download a copy of the entire application, including the database before running the code.

The code for the first page is shown as follows: -

Page: default.asp

<%
'Connects to database using recordset method
Function dataConn(database,connection,recordset)
    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")
    connection.Open "DBQ=" & Server.Mappath(database) & ";Driver={Microsoft Access Driver (*.mdb)};"
End Function
%
<HTML
<HEAD
    <TITLEPoll Example</TITLE
</HEAD

<BODY
    <FORM name="languages" method=post action="pollResults.asp"
    <PWhat is your favoutrite language?</P
<%
'Calls dataConn function to open dbPoll.mdb
dataConn "files/dbPoll.mdb",POdc,LArs

'Selects all fields within tblLanguages
LArs.Open "SELECT * FROM tblLanguages", POdc

'Loop through and display each record within the database as a radio button
Do While Not LArs.EOF
    Response.Write LArs("Language") & ": <INPUT type=radio name='language' value='" & LArs("Language")
& "'<BR"
    LArs.MoveNext
Loop

'Close database connection
LArs.Close
POdc.Close
Set POdc = Nothing
%
    <A href="pollResults.asp"View Poll</A
    <INPUT type=submit value="Vote"
    </FORM
</BODY
</HTML


Once connected to the database the script loops through each record, and displays that option as a radio
button. When the 'Vote' button is pressed, the individual value of the selected radio button is submitted
to the next page.

The code for the next page is shown below: -

Page: pollResults.asp

<%
'Define all variables that will be used
Dim I, Percent

'Connects to database using recordset method
Function dataConn(database,connection,recordset)
    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")
    connection.Open "DBQ=" & Server.Mappath(database) & ";Driver={Microsoft Access Driver (*.mdb)};"
End Function
%
<HTML
<HEAD
    <TITLEPolling Sample</TITLE
</HEAD

<BODY
<%
'Calls dataConn function to open dbPoll.mdb
dataConn "files/dbPoll.mdb",POdc,LArs

'Selects all fields within tblLanguages
LArs.Open "SELECT * FROM tblLanguages", POdc,1,2

'Loop through and total up number of votes for all records
Do While Not LArs.EOF

    'If record contains voted language then increment votes
    If
展开更多 50%)
分享

猜你喜欢

创建一个Web投票系统

ASP
创建一个Web投票系统

一个投票系统的源程序(coveryourasp.com)

ASP
一个投票系统的源程序(coveryourasp.com)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

图标制作软件:如何从web图像创建一个图标

电脑网络
图标制作软件:如何从web图像创建一个图标

一个简单的PHP投票程序

PHP
一个简单的PHP投票程序

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

一个简单的投票机器人

编程语言 网络编程
一个简单的投票机器人

Windows7系统创建一个新账户的方法

电脑网络
Windows7系统创建一个新账户的方法

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

关于客户端用ASP参生报表

关于客户端用ASP参生报表

20例Windows XP操作系统优化技巧

20例Windows XP操作系统优化技巧
下拉加载更多内容 ↓