您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > ASP >

创建一个Web投票系统

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 22:04 点击:
下面zip文件:aspdir.co.uk/files/Article-11.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 users 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>
    <TITLE>Poll Example</TITLE>
</HEAD>

<BODY>
    <FORM name="languages" method=post action="pollResults.asp">
    <P>What 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)};"

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • WAP常见问题问答大全(四)
      • ASP开发必备:WEB打印代码大全
      • ASP调用系统ping命令
      • asp缓存技术
      • ASP教程:第三篇 ASP基础
      • 用ASP+XML打造留言本(4)
      • 关于ASP Recordset 分页出现负数解决方法及建议
      • 用asp怎样编写文档搜索页面(5)
      • ASP处理多关键词查询实例代码
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1