Jump to content

Vote System


Dethman

Recommended Posts

I am trying to make a vote system for a game of mine I need to figure out how to check each user to see witch one has the most votes

SELECT `username` FROM `user_users` WHERE `userid`='$USER_WITH_MOST_VOTES'

How do I come up with the variable "$USER_WITH_MOST_VOTES" ?

Link to comment
Share on other sites

If I were you, I'd create an additional column on the user_users table, and name it vote_count.

Everytime the user gets a vote, you will update the value in the database and increment it by 1.

 

Then to check the user with the most votes

 

<?php
// db connection info

$query = "SELECT MAX(`vote_count`) FROM `user_users`";
$result = mysql_query($query) or trigger_error(mysql_error());

?>

 

 

 

Link to comment
Share on other sites

SELECT `userid`, MAX(`vote_count`) FROM `user_users`

 

I think you need to display the structure of the database. All votes should be placed at a different table, then check the number of occurences there from the list of users from the users table.

 

This would makes things inefficient for a simple polling system. A seperate table would only be required if you wanted to record information about the user that voted, e.g. userid, date/time they voted, what they voted for etc.. or if you wanted to display 'pretty' percentage bar images etc.. for BOTH answers.

Link to comment
Share on other sites

Well I have a voting poll running... and I store it that way for various reasons:

 

1. its more flexible to changes.

2. you can history of votes.

3. if i were to add a new voting poll for a different purpose then I don't have problem extending.

4. cancelling of votes (not deleting) for a certain poll is possible without disabling user account or cancelling other polls.

5. and etc.

 

Usually, the poll i made, users can create new polls and questions and with that in mind, my database wil never be spoiled... unless there would be requests that would dramatically change the concept of the current existing poll.

 

But if it would be the simplest form of poll, then Wolphie's suggestion would work. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.