This Blog is Moving to http://blog.drisgill.com
Viewing By Entry / Main
November 12, 2005
I promised a while ago that if there weren't any problems with my polling plugin to blogCFC, that I would release it to everyone. So without further stalling on my part, here it is: blogCFC_Poll_Plugin_v1.0_beta.rar
Update: Oops, I just found a problem and fixed it, if you have already downloaded (before 9:18pm EST), please redownload.
I have only tested this on my own site so far, so for all I know it won't work at all on anyone else's configuration, that being sad, it should work fine. Also, I haven't tested on blogCFC 4.0 yet... so beware. Anywho, download it, try to install it... and let me know if there are problems and I will post some fixes here. It is currently coded for mysql, but I 'think' the code should work for other db's (it's pretty simple SQL).
Update: Oops, I just found a problem and fixed it, if you have already downloaded (before 9:18pm EST), please redownload.
Comments
yep, remember blogcfc appends those directory slashes.. the download is here:
http://www.drisgill.com/files/blogCFC_Poll_Plugin_v1.0_beta.rar
http://www.drisgill.com/files/blogCFC_Poll_Plugin_v1.0_beta.rar
Thanks dominick... I think the problem is my rich text editor that I use for some reason like to take my full path links and make them relative... dangit. Fixed now.
Hi, Nice work. FTI I removed 'ORDER BY poll_answers.answer ASC' as it sometimes displayed the questions in an odd order. As long as you add them in the order you want them to be answered it's cool.
MSSQL is:
--------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_answers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_answers]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_questions]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_questions]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_votes]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_votes]
GO
CREATE TABLE [dbo].[poll_answers] (
[answerID] [int] IDENTITY (1, 1) NOT NULL ,
[questionID] [int] NOT NULL ,
[answer] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_questions] (
[active] [int] NOT NULL ,
[questionID] [int] IDENTITY (1, 1) NOT NULL ,
[question] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_votes] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[answerID] [int] NOT NULL ,
[questionID] [int] NOT NULL ,
[ip] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
-----------------------------------
hope that helps...
http://succor.co.uk
MSSQL is:
--------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_answers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_answers]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_questions]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_questions]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[poll_votes]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[poll_votes]
GO
CREATE TABLE [dbo].[poll_answers] (
[answerID] [int] IDENTITY (1, 1) NOT NULL ,
[questionID] [int] NOT NULL ,
[answer] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_questions] (
[active] [int] NOT NULL ,
[questionID] [int] IDENTITY (1, 1) NOT NULL ,
[question] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_votes] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[answerID] [int] NOT NULL ,
[questionID] [int] NOT NULL ,
[ip] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
-----------------------------------
hope that helps...
http://succor.co.uk
Also your query in poll_answers.cfm should be the following for MSSQL (using percent isn't good practice i don't belive, but again nice pod :) ):
<cfquery name="getvotes" datasource="#dsn#">
SELECT poll_questions.question, poll_answers.answer, COUNT(poll_votes.answerID) AS total, COUNT(poll_votes.answerID) / #totalvotes.total# AS percentage, poll_votes.id, poll_votes.answerID, poll_votes.questionID, poll_votes.ip
FROM poll_votes INNER JOIN
poll_answers ON poll_votes.answerID = poll_answers.answerID INNER JOIN
poll_questions ON poll_votes.questionID = poll_questions.questionID
WHERE (poll_votes.questionID = #form.questionID#)
GROUP BY poll_votes.answerID, poll_votes.id, poll_questions.question, poll_answers.answer, poll_votes.questionID, poll_votes.ip
ORDER BY percentage DESC
</cfquery>
<cfquery name="getvotes" datasource="#dsn#">
SELECT poll_questions.question, poll_answers.answer, COUNT(poll_votes.answerID) AS total, COUNT(poll_votes.answerID) / #totalvotes.total# AS percentage, poll_votes.id, poll_votes.answerID, poll_votes.questionID, poll_votes.ip
FROM poll_votes INNER JOIN
poll_answers ON poll_votes.answerID = poll_answers.answerID INNER JOIN
poll_questions ON poll_votes.questionID = poll_questions.questionID
WHERE (poll_votes.questionID = #form.questionID#)
GROUP BY poll_votes.answerID, poll_votes.id, poll_questions.question, poll_answers.answer, poll_votes.questionID, poll_votes.ip
ORDER BY percentage DESC
</cfquery>
I'll give those a shot in MySql
actually if you do this you can remove the need for CF to do it in the code :)
------------
SELECT poll_questions.question, poll_answers.answer, COUNT(poll_votes.answerID) AS total, COUNT(poll_votes.answerID) * 100 / #totalvotes.total# AS percentage,
poll_votes.answerID
FROM poll_votes INNER JOIN
poll_answers ON poll_votes.answerID = poll_answers.answerID INNER JOIN
poll_questions ON poll_votes.questionID = poll_questions.questionID
WHERE (poll_votes.questionID = #form.questionID#)
GROUP BY poll_votes.answerID, poll_questions.question, poll_answers.answer
ORDER BY percentage DESC
-----------------
------------
SELECT poll_questions.question, poll_answers.answer, COUNT(poll_votes.answerID) AS total, COUNT(poll_votes.answerID) * 100 / #totalvotes.total# AS percentage,
poll_votes.answerID
FROM poll_votes INNER JOIN
poll_answers ON poll_votes.answerID = poll_answers.answerID INNER JOIN
poll_questions ON poll_votes.questionID = poll_questions.questionID
WHERE (poll_votes.questionID = #form.questionID#)
GROUP BY poll_votes.answerID, poll_questions.question, poll_answers.answer
ORDER BY percentage DESC
-----------------
Well, the reason for the cf doing some of the work, was I was hoping to keep the queries as simple possible for cross dbms stuff
