Jump to content

Recommended Posts

Hey all. I'm setting up a simple voting code on my website. I've got the basic stuff put down. But I've hit a wall. I'm not quite sure how to display who has the most votes. I've got the code that inputs the 1+ vote for whoever they are voting for but that is it. So how would I go about displaying whoever has the most votes at any given time? Some dbcount() kind of thing I'm guessing but eh. ???

Link to comment
https://forums.phpfreaks.com/topic/89121-voting-system/
Share on other sites

http://www.tizag.com/mysqlTutorial/mysqlcount.php - that might help. Otherwise, post a less vague question, preferably with some of the code you already have created in your efforts to solve this one.

 

And, I'll move this to MySQL help which is really where it belongs.

Link to comment
https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-456479
Share on other sites

Alright. Example time!  ;D

 

User A has 10 votes

User B has 10 votes

User C has 11 votes

 

So since User C has the most votes, he and only he would be displayed. Now, User D and E both vote for User A, giving him 12 votes, putting him in the lead which means that he is now displayed on the page rather than User C.

 

Link to comment
https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-456485
Share on other sites

errrrr.....

 

SELECT * FROM votes ORDER BY vote_count DESC LIMIT 10

 

That would give you the top 10 records ordered by votes descending.  (x, y so that y <= x, z so that z<=y, etc)

 

(That assumes you store it with votes per key, not logs of each actual vote.)

 

No offense, but errr... as AndyB is hinting, you should probably read some MySQL articles....

Link to comment
https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-457405
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.