文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页精文荟萃软件资讯 → 一个投票系统的源程序coveryourasp.com

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

时间:2004/10/7 19:18:00来源:本站整理作者:蓝点我要评论(0)


  SurveyDescr.asp

  <%

  // ============================================

  // NOTE: all source code downloaded from CoverYourASP was written by

  // James Shaw (unless stated otherwise), and is copyright (c) 2000 by

  // James Shaw. You may use this source code on your web sites, but

  // please don't publish or distribute in any way.

  //

  // I would appreciate an HTML comment in any code you use, i.e.

  //

  // (see Footer(), documented in SSI.asp for details on how to do this)

  //

  //

  //      Please contact me to discuss any ASP contract work you may have.

  //

  // ============================================

  // output relevant meta tags

  Init( "Survey your readers" );

  // output common top of page

  Header( 'Survey your readers' );

  // output page content

  Content ( );

  // output common bottom of page

  Footer( );

  // ============================================

  // the content of this page - every page has a function 'Content' that

  // is called above.

  // ============================================

  function Content ( )

  {

  Out ( '' );

  Out ( '' );

  }

  %>

  utils/Survey.asp

  <%

  // ============================================

  // NOTE: all source code downloaded from CoverYourASP was written by

  // James Shaw (unless stated otherwise), and is copyright (c) 2000 by

  // James Shaw. You may use this source code on your web sites, but

  // please don't publish or distribute in any way.

  //

  // I would appreciate an HTML comment in any code you use, i.e.

  //

  // (see Footer(), documented in SSI.asp for details on how to do this)

  //

  //

  //      Please contact me to discuss any ASP contract work you may have.

  //

  // ============================================

  // ============================================

  // display or process the named survey

  // ============================================

  function ProcessSurvey ( sName )

  {

  // has the survey form been submitted?

  if ( Request.Form.Count )

  {

  // connect to the database

  DBInitConnection ( );

  var sSurvey = "" + Request.Form ( "Survey" );

  // only update the survey when no cookie

  if ( "" == Request.Cookies ( sSurvey ) )

  {

  // get the data from the form and update the database

  // use an enumerator to get name and value

  var e = new Enumerator ( Request.Form );

  while ( !e.atEnd ( ) )

  {

  var oItem = e.item();

  // increment the current number of times this answer has been chosen

  oConnection.Execute ( 'UPDATE SurveyAnswers SET Hits=Hits+1 WHERE Question="' + oItem + '" AND

  Answer="' + Request.Form ( oItem ) + '";' );

  e.moveNext ( );

  }

  // note that setting cookie here assumes we are buffering

  // the Reponse.Writes - cookies must be set before any

  // HTML is sent to the client

  Response.Cookies ( sSurvey ) = "1";

  // I'm not setting the 'expires' on the cookie, so it'll go

  // away when the browser is closed. I just wanted to stop

  // the survey incrementing if the page refreshed.

  }

  // now display all the answers to the survey

  Out ( '

  Thanks for taking part in our "' + sSurvey + '" survey! The answers that everyone has

  given so far are shown below:' );

  // the last question we displayed

  var sLast = "";

  // get all the selected answers, sorted by question and hits

  DBGetRecords ( 'SELECT SurveyAnswers.Question,Answer,Hits FROM SurveyAnswers INNER JOIN

  SurveyQuestions ON SurveyQuestions.Question=SurveyAnswers.Question WHERE Survey="' + sSurvey + '" AND

  Hits>0 ORDER BY SurveyAnswers.Question,Hits DESC;' );

  var fScale;

  while ( !oRecordSet.EOF )

  {

  // display question when it changes

  var sIntQuestion = "" + oRecordSet ( 0 );

  // slice off chars used for sorting

  var sQuestion = sIntQuestion.slice ( 2 );

  // get answer

  var sIntAnswer = "" + oRecordSet ( 1 );

  // slice off chars used for sorting

  var sAnswer = ExpandMacros ( sIntAnswer.slice ( 2 ) );

  var nReaders = oRecordSet ( 2 ) - 0;

  if ( sQuestion != sLast )

  {

  Out ( '

  ' + sQuestion + '

  ' );

  sLast = sQuestion;

  Out ( '"' + sAnswer + '" was the top answer (' + nReaders + ' readers)

  ' );

  fScale = 300.0 / nReaders;

  }

  else

  {

  Out ( '"' + sAnswer + '" was chosen by ' + nReaders + ' readers

  ' );

  }

  Out ( '

  ' );

  oRecordSet.MoveNext ( );

  }

  // release the connection ASAP

  DBReleaseConnection ( );

  }

  else

  {

  // some initial instructions

  Out ( '

  There aren\'t any important instructions when answering these questions - except you

  don\'t have to answer any. All are optional - if you don\'t like a question, or none of the answers are

  relevant, just move onto the next one!' );

  // connect to the database

  DBInitConnection ( );

  // get the questions from the database

  DBGetRecords ( 'SELECT Question FROM SurveyQuestions WHERE Survey="' + sName + '" ORDER BY

  Question;' );

  if ( oRecordSet.EOF )

  {

  Out ( 'No questions were found for survey "' + sName + '"

  ' );

  return;

  }

  // store the questions in an array

  var sIntQuestions = new Array;

  var nQuestions = 0;

  while ( !oRecordSet.EOF )

  {

  sIntQuestions [ nQuestions++ ] = "" + oRecordSet ( 0 );

  oRecordSet.MoveNext ( );

  }

  Out ( '' );

  // some hidden fields to pass data through to results page

  Out ( '' );

  // now loop through the questions

  for ( var nQuestion=0; nQuestion<nQuestions; nQuestion++ )

  {

  var sIntQuestion = sIntQuestions [ nQuestion ];

  // slice off chars used for sorting

  var sQuestion = sIntQuestion.slice ( 2 );

  // get the answers from the database

  DBGetRecords ( 'SELECT Answer,AnswerType FROM SurveyAnswers WHERE Question="' + sIntQuestion + '"

  ORDER BY Answer;' );

  Out ( '

  ' + sQuestion + '

  ' );

  while ( !oRecordSet.EOF )

  {

  // get the answer

  var sIntAnswer = "" + oRecordSet ( 0 );

  // slice off chars used for sorting

  var sAnswer = ExpandMacros ( sIntAnswer.slice ( 2 ) );

  var sAnswerType= "" + oRecordSet ( 1 );

  switch ( sAnswerType )

  {

  case 'radio':

  Out ( '' +

  sAnswer );

  break;

  default:

  break;

  }

  Out ( '

  ' );

  // get next answer

  oRecordSet.MoveNext ( );

  }

  }

  Out ( '

  ' );

  Out ( '

  ' );

  // release the connection ASAP

  DBReleaseConnection ( );

  }

  }

  // ============================================

  // add links to text where *? macros are found, e.g. *d expands to

  // Send a donation!

  // NOTE: currently assumes expansions are always at end of line

  // ============================================

  function ExpandMacros ( sText )

  {

  var sMacros = new Array (

  '**',

  '*d'

  );

  var sExpansions = new Array (

  'You need to send me feedback!',

  'send a donation!'

  );

  for ( var i=0; i<sMacros.length; i++ )

  {

  var nPos = sText.indexOf ( sMacros [ i ] );

  if ( -1 != nPos )

  {

  sText = sText.slice ( 0, nPos ) + sExpansions [ i ];

  break;

  }

  }

  return sText;

  }

  %>

  utils/Database.asp

  <%

  // ============================================

  // NOTE: all source code downloaded from CoverYourASP was written by

  // James Shaw (unless stated otherwise), and is copyright (c) 2000 by

  // James Shaw. You may use this source code on your web sites, but

  // please don't publish or distribute in any way.

  //

  // I would appreciate an HTML comment in any code you use, i.e.

  //

  // (see Footer(), documented in SSI.asp for details on how to do this)

  //

  //

  //      Please contact me to discuss any ASP contract work you may have.

  //

  // ============================================

  // globals

  var oConnection;

  var oRecordSet;

  // enums

  // Connection.State and Recordset.State property

  var adStateClosed = 0;         // the object is closed.

  var adStateOpen = 1;             // the object is open.

  var adStateConnecting = 2;   // the object is connecting.

  var adStateExecuting = 4;      // the object is executing a command.

  var adStateFetching = 8;         // the rows of the object are being fetched.

  // Recordset.Cursor property

  var adOpenUnspecified = -1;   // does not specify the type of cursor.

  var adOpenForwardOnly = 0;   // (default) a forward-only cursor, i.e. you get only one pass thru the data!

  var adOpenKeyset = 1;         // can go in any direction, and as a bonus you'll see changes other users

  make. EXPENSIVE!

  var adOpenDynamic = 2;      // as Keyset, but also you can see additions/deletions other users make.

  EXPENSIVE!

  var adOpenStatic = 3;         // can go in any direction, but read-only.

  // Recordset.LockType property

  var adLockUnspecified = -1;   // does not specify a type of lock.

  var adLockReadOnly = 1;      // (default) guess!

  var adLockPessimistic = 2;      // guaranteed to work

  var adLockOptimistic = 3;      // records locked only when you call Update. fingers crossed

  var adLockBatchOptimistic = 4;// required for batch update mode

  // ============================================

  // example usage:

  //      DBInitConnection ( );

  //

  //      DBGetRecords ( "SELECT * FROM Somewhere" );

  //

  //      ...use oRecordSet

  //

  //      DBReleaseRecords ( );      // optional step

  //

  //      DBGetRecords ( "SELECT * FROM SomewhereElse" );

  //

  //      ...use oRecordSet

  //

  //      DBReleaseRecords ( );      // optional step

  //

  //      DBReleaseConnection ( );

  // ============================================

  // ============================================

  // initializes database variables for first use on page - leave it to the

  // last possible second before calling this function

  // ============================================

  function DBInitConnection ( )

  {

  // don't open it again if already opened!

  if ( oConnection != undefined )

  return;

  // you can open Recordset objects without a Connection object, but

  // it's far less efficient if you are opening multiple Recordsets.

  //

  // if you don't create a Connection object ADO creates a new one for

  // each new Recordset.Open, even if you use the  connection string.

  oConnection = Server.CreateObject( 'ADODB.Connection' );

  // open the database - use MapPath to make relative path into physical path

  // NOTE: keep your database path a secret - nasty people are everywhere!

  // 2. change the 4.0 to 3.51 when using Access 97

  oConnection.Open( 'Provider=Microsoft.Jet.' + sDBDriver + '; Data Source=' + Server.MapPath (

  sDBPath ) );

  // create a Recordset

  oRecordSet = Server.CreateObject( 'ADODB.Recordset' );

  }

  // ============================================

  // tidies up after DBInitConnection

  // ============================================

  function DBReleaseConnection ( )

  {

  // don't release the connection if not connected!

  if ( oConnection == undefined )

  return;

  // close and delete the Recordset object

  DBReleaseRecords ( );

  oRecordSet = undefined;

  // Don't call Close if the Recordset failed to Open properly, i.e. its

  // State is still adStateClosed (0)

  if ( oConnection.State != adStateClosed )

  oConnection.Close();

  oConnection = undefined;

  }

  // ============================================

  // executes the passed in SQL statement and returns a read-only

  // forward-only oRecordSet object

  // ============================================

  function DBGetRecords ( sSQL )

  {

  // if the Recordset is already open, close it

  DBReleaseRecords ( );

  // we could use oRecordSet = oConnection.Execute( sSQL ) here

  // but then we will always get back a read-only, forward-only cursor.

  // (admittedly this is the most used type, but still)

  // use oRecordSet.Open and we have far more control. For details

  // read the definitions of the enums at the top of this file.

  // remember that this can fail if passed garbage, and hence the

  // Recordset will remain closed, State == adStateClosed

  oRecordSet.Open ( sSQL, oConnection, adOpenForwardOnly, adLockReadOnly );

  }

  // ============================================

  // tidies up after DBGetRecords

  // ============================================

  function DBReleaseRecords ( )

  {

  // when you have finished with an open Recordset object, call the

  // Close method to release its resources. You can call Open again.

  // Don't call Close if the Recordset failed to Open properly, i.e. its

  // State is still adStateClosed

  if ( oRecordSet != undefined && oRecordSet.State != adStateClosed )

  oRecordSet.Close();

  }

  %>

  ' );

  // if the survey hasnt been submitted yet...

  if ( !Request.Form.Count )

  {

  //...display some blah, blah

  Out ( 'Finally, surveys come to CoverYourASP! I\'ve been wanting to ask you guys and gals

  questions for a long time, and now I can. It\'s up to you if you want to answer of course!' );

  Out ( '

  Of course, the real benefit to you is that if you tell me what you like I\'ll probably

  provide it. If you send in your donations the probability increases rather

  dramatically!' );

  Out ( '

  Take the example survey below if you have the time and inclination. I plan to post more

  in a special survey category, and start offering incentives to take them.' );

  Out ( '

  Afterwards, look at the code. I think you\'ll be surprised how simple it is to create

  surveys with this code. This page has one function call in it, with just one parameter - the name of the

  survey! All questions, answers and results are stored in the database.' );

  }

  // show the survey, or process it's input

  ProcessSurvey ( 'Who are you and what do you think?' );

  if ( !Request.Form.Count )

  Out ( '

  <img src="images/source.gif" align="right"

  border=0>Please submit the survey first before looking at the source code - this link is on the result

  page too!' );

  else

  Out ( '

  <img src="images/source.gif"

  border=0>' );

  Out ( '

  ' );

  // show rotating banners

  ShowBanners ( 4 );

  Out ( '

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本