Re: Real-Time Polling Results

by Frank Boumphrey <bckman(at)ix.netcom.com>

 Date:  Mon, 11 Feb 2002 17:40:20 -0500
 To:  hwg-techniques(at)hwg.org,
"SARVER,
LAURA (HP-USA,
ex3)" <laura_sarver(at)hp.com>
 Cc:  frank(at)hwg.org
 References:  hp
  todo: View Thread, Original
No need for a data base really you could store the information in a text
file if you wanted. But lets say you are using a DB.

Any way what ever the language here is the way to do it

Ask the question, and submit the answer via a web form.

<form action='poll.asp'>
Which do you prefer?
Cats <input type = 'radio' name='rb' value='cats'><br />
Dogs <input type = 'radio' name='rb' value='dogs'><br />
<input type = 'submit' name='rb' value='cats'><br />
</form>


Your database needs one table with one ID field and two INT fields named
'catnums' and 'dognums' and one record! Call the id field 'pollnumbers' and
the table 'pollfigures'

if you are using asp and vbscript
Here is some of poll.asp
(please note this script is not debugged :>))
<%
'get the result of the poll
dim pollresult
 pollresult=request("rb")

'open the data base
dim oConn, strConn
 strConn="[put connection string here]"
  set oConn=server.createObject("ADODB.connection")
 oConn.open strConn
'create a record set and select the solitary record
 dim strSQL,oRS
 strSQL="SELECT * FROM pollfigures WHERE ID='pollnumbers';"
  set oRS=server.createObject("ADODB.recordset")

 oRS.open strSQL, oConn

' find the existing numbers
 dim dognums,catnums
   dognums=oRS("dogs").value
   catnums=oRS("cats").value
'add the submission result
  if pollresult="dogs" then
    dognums=dognums+1
 else pollresult="cats then
   catnums=catnums+1
 end if

' display the results
 response.write "You voted for " & pollresult & "<br />"
response.write dognums & " have voted for dogs " & catnums & " have voted
for cats.<br />"

' update the database
strSQL="UPDATE pollfigures SET catnums=" & catnums & "' dognums=" & dognums
& " WHERE id='pollnumbers';"

  oConn.execute strSQL
 'housekeeping
  oRS.close
  set oRS=nothing
  oConn.close
  set oConn=nothing
%>


You can also convert the numbers into a graphic. If you use PHP, you could
make a nice pie graph, but using ASP you will have to settle for a bargraph!
Frank


----- Original Message -----
From: "SARVER,LAURA (HP-USA,ex3)" <laura_sarver(at)hp.com>
To: <hwg-techniques(at)hwg.org>
Sent: Monday, February 11, 2002 3:59 PM
Subject: Real-Time Polling Results


> Hi all,
>
> I'm hoping someone can help me get started with this project.  I have
> received a request to put up a poll on our internal website.  We need to
be
> able to let the user respond to a question and also display the current
> results in a graphic format. I've found some sites that do this such as
> http://www.rollingstone.com/ but I can't figure out how it all fits
together
> from the source code I can see.  I assume there's a database that the form
> submittal is stored in but beyond that I'm lost for displaying the
graphic.
>
> I have some experience with JavaScript, ASP and Access databases and have
> teammates with ColdFusion and Perl experience.  We'd probably be putting
the
> form on an NT server.  Using PHP isn't a possiblity.
>
> Any help you could pass my way would be very much appreciated.
>
> Thanks,
> Laurie
>
>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA