List Info

Thread: Voting Results, how to tabulate




Voting Results, how to tabulate
user name
2006-05-13 13:23:16
I have created a php voting app that sends the results to a
mysql
database, it is for our school elections, how do I create a
results
page where it will count the number of times a student
received a vote
for lets say president and then return the results with
their name next
to it. For example it would report John Doe - 5 votes, Jane
Doe 4
votes, etc.


Any help is greatly appriciated, I thank you all in advance.


Mike


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

Voting Results, how to tabulate
user name
2006-05-13 14:22:53
Come on, we need a bit more information than that!

But, you might like to look at the GROUP BY statement


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

Voting Results, how to tabulate
user name
2006-05-14 00:13:11
What info do you need? The database has an ID field as the
primary key,
and then the voting category field, i.e. President,
Vice-President,
etc. These fields are varchar 30 and are populated with
names of
students. PHP version is 5, Apache3 is 2 and not quit sure
about mysql,
I think it is 4.3.

Any thing else let me know...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

Voting Results, how to tabulate
user name
2006-05-14 16:26:16
OK, so the table looks something like this?:

|voter_id |president |vice-president |deputy   |drummer|
|001       |john        |paul               |george   |ringo
    |
|002       |john        |george           |ringo      |john 
    |
|003       |paul        |john               |george   |ringo
    |
|004       |ringo       |paul               |john      
|george  |

In that case I think the query should be like this:

SELECT DISTINCT (
v1.president
) AS candidate, COUNT( v2.president ) AS total_votes
FROM votes v1
LEFT JOIN votes v2 ON v1.voter_id = v2.voter_id
GROUP BY candidate
ORDER BY total_votes DESC;


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )