i'm doing php project on e-voting and i've a data goes from voters in the databse can u help me to give me the php code that counts the votes in voting seesion and display the result..plzzzzz

Recommended Answers

All 2 Replies

mysql> select count(vote) as total, vote from votes group by vote;

will show you the total of votes per distinct vote entry.

thanx rob...i need to ask u a question. Is it the same that we 're using different table 'vote'. to store votes. did i ve to use this code for this matters?

OK, so here's the query I presented

select count(vote) as total, vote from votes group by vote

the syntaxt would be like this

select count(column) as total, column from table group by column;

what this is doing is for each distinct vote, counting the amount of votes that match that distinct vote, hence group by column. So if I had a table called polvotes and my columns were candidates and voter which stores the name of the voter and the candidate the voter voted for. The only thing that I am really concerned about is the candidate column and the number of votes per distinct candidate so my query would be:

select count(candidates) as total, candidates from polvotes group by candidates

I hope this explains what is going on and I hope that helps. It is a very simple design but ultimately that is what it comes down to. Then your program would then parse the results and do whatever with them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.