当前位置: 首页 > 图文教程 > 网络编程 > ASP > 创建一个Web投票系统

ASP
isNull(str), isEmpty(str)和 str = 的区别
使用ADO批量更新记录(源代码)
自己动手,结合javascript和dhtml做一个ubb编辑器
检查Email地址的比较完善的正则表达式函数
从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
ASP环境下邮件列表功能的实现 (四)(推荐)
在ASP应用中如何限制同一表单被多次提交!!!!好东西
了解MSMQ,控制ASP进程 (一)
了解MSMQ,控制ASP进程 (二)
ASP技术在论坛中的运用(一)(吐血推荐!!!!)
ASP技术在论坛中的运用(二)(吐血推荐!!!!)
ASP技术在论坛中的运用(三)(吐血推荐!!!!)
ASP技术在论坛中的运用(四)(吐血推荐!!!!)
ASP技术在论坛中的运用(五)(吐血推荐!!!!)
ASP技术在论坛中的运用(六)(吐血推荐!!!!)
ASP技术在论坛中的运用(七)(吐血推荐!!!!)
ASP技术在论坛中的运用(八)(吐血推荐!!!!)
不用数据源打开数据库(DSNless connection)
大部分的ADO的错误码对应的含义
好东西,翻页程序,大家可以参考

ASP 中的 创建一个Web投票系统


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 63 ::
收藏到网摘: n/a

  下面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>
    <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)};"
End Function
%>
<HTML>
<HEAD>
    <TITLE>Polling 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