动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP实例 ]的信息

本月文章推荐
.使用 ASP+ 列表绑定控件(下).
.用asp生成wml.
.从数据库中动态选取下拉列表的方.
.利用ASP将HTML格式数据传输给Exc.
.ASP实现播放Flash的例子.
.实例演练ASP+XML编程(4).
.用ASP开发一个在线考试程序(九).
.各种存储过程使用指南.
.网络寻呼机数据库版发送消息tome.
.ASP实现网站智能分词搜索.
.一个功能完善的专栏管理的程序-&.
.深入讲解 ASP+ 验证(一).
.怎样做自己的二级域名(之二).
.一个免费的邮件列表源程序(二).
.精彩OUTLOOK 2000组件放送.
.使用FSO把文本信息导入数据库.
.一个投票系统的源程序(coveryour.
.全文本检索的应用(2).
.无组件上传图片至SQLSERVER数据库.
.利用ASP.NET设计FTP文件上传(中).

创建一个Web投票系统

发表日期:2001-8-22 |


下面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 LArs("Language") = Request.Form("language") Then
          LArs("Votes") = LArs("Votes") + 1
          LArs.Update
    End If
    I = I + LArs("Votes")
    LArs.MoveNext
Loop

'Calculate value which will be used to calculate percentage
Percent = 100 / I
LArs.MoveFirst

'Loop through and recalculate percentage of votes for each record
Do While Not LArs.EOF
    LArs("Percentage") = LArs("Votes")*Percent
    LArs.Update
    LArs.MoveNext
Loop
LArs.Close

'Selects all fields within tblLanguages
LArs.Open "SELECT * FROM tblLanguages ORDER BY Percentage DESC", POdc

'Loop through and display all updated records
Do While Not LArs.EOF
    Response.Write "<B>" & LArs("Language") & "</B><I> (Votes: " & LArs("Votes") & ")</I>"

    'Set pixel-width of table cells to percentage number
    Response.Write"<TABLE cellpadding=0 cellspacing=0 height=10 width=" & LArs("Percentage") & "
bgcolor=" & LArs("BarColour") & ">"
    Response.Write"<TR><TD></TABLE>" & LArs("Percentage") & " %<BR>"
    LArs.MoveNext
Loop

'Close database connections
LArs.Close
POdc.Close
Set POdc = Nothing
%>

</BODY>
</HTML>


The second page first retrieves the selected option from the form submitted by the user. The page then
loops through each record and calculates the total number of votes in order to find out what number of
votes is equal to 1%. When the page finds the record that the user submitted, presuming a value was
submitted at all, the number of votes for that option is incremented.

Using the value which determines how many votes are equal to 1%, we again loop through each record and re-
calculate the percentage of votes each option has received by multiplying this previously determined value
by the number of votes that option has received. It's all 10 y/o maths stuff really, so be very ashamed of
yourself if you're finding this difficult, :P.

Once the records have been updated, all that is left to do is simply loop through each record in
descending order of their percentage.

The small bar underneath each option is just a table cell with it's pixel-width determined by the
percentage of that particular option. All in all it's pretty simple stuff, just takes a bit of work to fix
it all together.

Have a Nice Day,
                    sTePHeN ;)

上一篇:使用JScript.NET创建asp.net页面(七) 人气:11060
下一篇:W3 Jmail中文使用说明 人气:15302
浏览全部投票的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-12-4 PhpCMS2008 bulid 081203 简体中
2008-12-4 Menalto Gallery v1.5.10 多国语
2008-12-4 Phpcms2008 bulid 081203 简体中
2008-12-4 乘风多用户计数器 v3.92 (Acc)
2008-12-4 乘风多用户计数器 v3.92 (Sql)
2008-12-4 BBSxp 2008 8.0.5 SP2 Build 081
2008-12-4 ASBLOG v2.5 bulid 081118(1201)
2008-12-4 非零坊幽默短信 v3.4
2008-12-4 红茶巴士(公交)查询系统 v3.0
2008-11-29 Tencent Traveler 4.4
2008-11-29 龙卷风网络收音机 v3.0.0.0
2008-11-29 Intel Chipset Software Install
2008-11-29 TweakVI 1.0 Build 1100
2008-11-29 Opera 9.62 Build 10469
2008-11-29 MPlayer WW编译版 SVN-r28044(20
2008-11-29 NetTools网络工具v1.0.0破解版
2008-11-29 3DGallery三维体验1.1破解版
2008-11-29 SecretBook保密本v1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | OPEN参数生成器 | 弹出式窗口代码产生器 | 密码登录生成器 | 在线按钮生成器 | Meta标签生成器 | 多色彩特效字代码生成器 | 网页代码调试器 | 在线FTP登陆 | Flash取色器 | 配色代码对照表 | 配色辞典 | CSS生成器 | 广告代码 | 框架网页代码生成器 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | 在线调色板 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 元素周期表 | 健康查询 | 世界时间 | 万年历 | 二十四节气 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2009 www.knowsky.com All rights reserved | 沪ICP备05001343号