PDA

View Full Version : Getting Poll Count


Boofo
05-27-2003, 07:52 AM
I'm trying to pull how many polls there are in each forum but I can't seem to get the query quite right. Can anyone please tell me what I am doing wrong?

$poll = $DB_site->query_first("SELECT COUNT(pollid) as count FROM poll
LEFT JOIN thread ON (post.threadid = thread.threadid)
WHERE thread.forumid=$forumid
GROUP BY poll.pollid
");

Gary King
05-28-2003, 07:10 PM
$poll = $DB_site->query_first("SELECT COUNT(poll.pollid) AS count FROM poll
LEFT JOIN thread ON (poll.pollid=thread.pollid) WHERE thread.forumid=$forumid");

Boofo
05-28-2003, 07:22 PM
Thank you, sir. ;) That did the trick. Can I use this query to also get the total voters and votes, too?

Gary King
05-28-2003, 07:30 PM
Total voters and votes per poll or per forum? And don't you mean only total votes, because # of voters = # of votes, unless you mean unique voters.

Boofo
05-28-2003, 07:47 PM
Which would be the best way to go? Probably total unique voters per forum? And maybe the average votes per poll per forum?

Gary King
05-28-2003, 10:03 PM
Those would require some more extensive queries. Please create a query first, and when you get stuck, then reply back.

Boofo
05-28-2003, 10:04 PM
It can't be done with the above query with a JOIN or something?

Gary King
05-29-2003, 12:04 AM
The average votes per poll per forum:

$poll = $DB_site->query_first("SELECT COUNT(poll.pollid) AS count, SUM(voters) AS voters FROM poll
LEFT JOIN thread ON (poll.pollid=thread.pollid) WHERE thread.forumid=$forumid");

$averagevotes=$poll['voters']/$poll['count'];


Use $averagevotes wherever you need it.

Boofo
05-29-2003, 12:32 AM
Ok, that works. The only problem is if you have a multiple choice poll in there the count is off for the voters.

Gary King
05-29-2003, 12:44 AM
You'd have to go into pollvote for total unique voters per forum and for multiple choice polls.

Boofo
05-29-2003, 12:47 AM
A whole new query, right? ;)

Gary King
05-30-2003, 12:48 AM
Yep, pretty much.

Boofo
05-30-2003, 01:22 AM
Ok, thanks.

Boofo
06-04-2003, 04:29 AM
Mods, you can close this thread.