![]() |
Poll Vote Percentages
Hey all,
I think I got my poll to how I want it to work, though usually in my case, I get some form of an error, but I'll cross that bridge when I get to it. Any who... I basically want to calculate the percentage of the votes in my poll, so if their was one vote for 'yes' and one for 'no' then each would be 50%... you get the idea, I hope. I'm no good with math in PHP, hell... math in general. Below is a structure of my poll tables, just to give you an idea of how things are laid out, so hope it helps. poll
|
You need to
COUNT(*) all the choices that pertain to the poll_id you're after. Say you've got a total of 9 votes, take the 9 and store it. Then get all the options you have, COUNT them individually whilst using GROUP BY on the option they can select.So if you have 5 yes, and 4 no, making a total of 9. You would do it like this (in pseudo form): Code:
GET YES = 5 |
Hey,
Thanks for the response, I'll definitely try that, though I'll admit I've never really had to use GROUP BY, so I'm not 100% on that one. If you helped later on, that'd be great! :D |
Poll sample
Hi, this is my first post... A way back I did a simple poll for a web site, here is a snippet from the code that displayed everything: (its an excrept from a class, but everything you need should be there)
PHP Code:
|
It also uses MSSQL, so its slightly different from mysql.
|
Hey trmbne2000, thanks for the response, it's helped a bit.
Could I show you my function I've wrote? Perhaps someone may want to work off that? I'm not asking "Hey, do this for me" because that's the last thing I care for, as how else am I to learn, but, in this case, I've had an hectic two weeks in trying to find a job, and I always seem to have plans, so... if anyone could use my code and let me know what I could do to get the results I want, I'd appreciate it a lot! PHP Code:
Off topic: I got the PM about the "award" not sure if I was given this personally by Wildhoney, or if you get it after the post count reaches the limit... either way, thanks! |
Remaining off-topic for the moment. All of them are personally handed out :-)
|
Ok, the one thing I see is this line:
PHP Code:
|
| All times are GMT. The time now is 11:14 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0