thewhat Posted February 3, 2008 Share Posted February 3, 2008 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. ??? Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/ Share on other sites More sharing options...
AndyB Posted February 3, 2008 Share Posted February 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-456479 Share on other sites More sharing options...
thewhat Posted February 3, 2008 Author Share Posted February 3, 2008 Alright. Example time! 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. Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-456485 Share on other sites More sharing options...
AndyB Posted February 3, 2008 Share Posted February 3, 2008 http://www.tizag.com/mysqlTutorial/mysqlmax.php You could have found that yourself on the page I linked you to before. Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-456533 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 not following. why don't you just select from the database where the number of votes is highest and then echo it? Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-457218 Share on other sites More sharing options...
corbin Posted February 4, 2008 Share Posted February 4, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/89121-voting-system/#findComment-457405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.