Jump to content

Vote System


Dethman

Recommended Posts

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
https://forums.phpfreaks.com/topic/113871-vote-system/#findComment-585150
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
https://forums.phpfreaks.com/topic/113871-vote-system/#findComment-585171
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
https://forums.phpfreaks.com/topic/113871-vote-system/#findComment-585966
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.