创建一个Web投票系统

2016-01-29 17:33 10 1 收藏

创建一个Web投票系统,创建一个Web投票系统

【 tulaoshi.com - ASP 】

  下面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

来源:http://www.tulaoshi.com/n/20160129/1501925.html

延伸阅读
本教程,我们会教你使用混合工具如何绘制小鱼,使用旋转扭曲工具,使用扭转效果,使用收缩和膨胀效果,如何制作海藻形状。让我们开始创建一个海底世界吧! 成品图预览 下面是我们要创建的最后设计稿。 1. 绘制如图所示的形状。我绘制了4个形状,一个是白色填充的鱼的外形;然后是小镰刀形状,填充蓝色;下一个是填充黄色的形状,大小是鱼外...
第一步:在一个新场景里建立一个cube(立方体),到Smooth(光滑)选项,将细分级别调整到3. 你的立方体现在看起来应该如下图所示。 如下图所示,选择你模型的1/6的面,然后删掉其余的面。 第三步,如下图在箭头所指的第三个面2/3的位置添加一圈环边,把你的模型分成三部分,我使用MJ POLY TOOLS插件来分割,它能帮我得到良好的测...
void __fastcall TForm1::FormCreate(TObject *Sender) {  SetWindowLong(TreeView1-Handle,GWL_STYLE, GetWindowLong(TreeView1-Handle,GWL_STYLE) | TVS_CHECKBOXES); } //判断一个节点是否处于Checked状态 bool GetNodeChecked(TTreeNode *ANode) { TVITEM tvItem; tvItem.mask = TVIF_HANDLE | T...
标签: Web开发
从开始学习到使用ASP到现在也写了不少程序了,最令人头痛的是写数据分页,每次都是由于几个变量名或几个参数的不同,因而需要每次都写哪一段冗长而又繁杂的分页代码,代码长了使得程序的可读性变差,容易出差,调试半天也找不出错在哪里,所以慢慢的我开始使用一些网上的提供的分页函数或分页类。的确省事不少,但是通常的函数和类的做法都是就...
标签: Web开发
下面通过创建一个鼠标滑过加亮显示的 HTC 来演示一下创建 HTC 的过程。 1、创建 HTC 文件的架构。一个标准的 HTC 文件含有一个 SCRIPT 块和一对可选的 COMPONENT 标记。 PUBLIC:COMPONENT SCRIPT /SCRIPT /PUBLIC:COMPONENT 2、写一个可执行的脚本。 在下面的代码中,ATTACH 被用于设置 HTC 接收元素在 onmouseover 和 onmouse...

经验教程

19

收藏

7
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部