Solved

Code for Simple Polling Question - Single Question w/ 3-4 Optional Answers

Posted on 2008-10-28
4
247 Views
Last Modified: 2013-12-24
Good Morning.
I am searching for the code needed to create a single polling question on an index.cfm page on our site.  It will be a single question with 3 or 4 possible answers.  Something like:  

How often do you visit our site?
- Daily
- Weekly
- Monthly
- Never

Once visitor selects the answer, a new, small window will open and display the results of the current poll.  The polling question and answers will change monthly and we have no need to store past polling results and/or data.  

I have done lots of searching for a simple solution with no luck thus far.  So any help would be greatly appreciated!!
0
Comment
Question by:cindyredo
  • 2
4 Comments
 
LVL 16

Expert Comment

by:duncancumming
ID: 22826118
Take a look at Soundings:
http://soundings.riaforge.org/
0
 
LVL 10

Accepted Solution

by:
Mr_Nil earned 500 total points
ID: 22826680
Hi Cindy,

Unfortunately dynamic poll's are never that simple to write and not that easy to post a complete response on somewhere like Experts Exchange.  You will have to fill in the blanks yourself.

For a dynamic poll you're going to need 3 tables in your database.  The first table is a "question" table, the second is an "options" table and the third is "answers".

The question table should look something like this :
QuestionID Int AutoNumber PrimaryKey
QuestionText Text
StartDate DateTime

The option table should look something like this :
OptionID Int AutoNumber PrimaryKey
fkQuestionID Int ForeignKey
OptionText varchar(100)
DisplayOrder int

The Answer Table should look something like this:
AnswerID Int AutoNumber PrimaryKey
fkSelectedOptionID Int ForeignKey

You'll probably want to add some fields to the answer table to record who made that answer and possible help protect against abuse.

You'll need to create some CRUD (Create, Read, Update, Delete) functions to allow you to manage the Question text, its start date and its associated options and order the options so that the display the way you want them to.

You'll need a function to select the question for the current month using the start date and display a form displaying the question and the options as radio buttons. When the form is submitted you'll need to save the selected answer and any information from the user you require.  To display the graph of responses use CFChart and a group by query of the latest question, its options and the count of answers eg.

SELECT Q.QuestionID, Q.QuestionText, O.OptionID, O.OptionText, Count(A.AnswerID) AS AnswerCount
FROM tblQuestion AS Q
INNER JOIN tblOption AS O ON Q.QuestionID = O.fkQuestionID
INNER JOIN tblAnswer AS A ON O.OptionID = A.fkOptionID
WHERE Month(Q.StartDate) = Month(Now()) AND Year(Q.StartDate) = Month(Now())
GROUP BY Q.QuestionID, Q.QuestionText, O.OptionID, O.OptionText
ORDER BY O.DisplayOrder

As I hope I've indicated there is a lot to think about and a lot of code associated with it. Far too much to post and explain on here and it occurs to me....  Why am I when I can simply point you to Ray Camden's Soundings application on RIAForge.org - http://soundings.riaforge.org/  ;)
0
 

Author Comment

by:cindyredo
ID: 22841977
Thank you for your comments.  I was hoping there was a way to accomplish this without having to store data in a database...the server where this site resides does not have SQLServer installed.  What is this Soundings application, I took a look, but did not understand.
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 22844223
hahaha, trying to do a poll without a database is going to be very difficult!  the only real alternative would be to write everything to file every time someone votes in the poll, and read the file(s) to work out what the ongoing scores are at any time.... very far from ideal.

there are other databases of course, many of them free.  you could even try treating something like excel as a datasource.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now