rynoa164 Posted April 24, 2008 Share Posted April 24, 2008 Hi everyone! I'm brand-new to PHP and I am making a site where people can rate people's answers to questions. So far I've gotten the front page to randomly generate questions for users to answer, then the answers go into a database. All of the answers to one question at a time is displayed. Next to each answer I would like a thumbs up/down graphic. Upon clicking either, I want a +1 or -1 value to be added to their rank. In my MySQL table, the table is called "answer" and the row (?) is called "a_rank". I have no idea how to go about programming this but I have a feeling it's relatively easy. Any help would be much appreciated! Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/102634-rankvoting-system/ Share on other sites More sharing options...
Spaceman-Spiff Posted April 24, 2008 Share Posted April 24, 2008 The SQL query should be something like this: UPDATE answer SET a_rank = a_rank + $modifier WHERE a_id = $aid LIMIT 1; fill in $modifier with 1 or -1, $aid with the table ID. Link to comment https://forums.phpfreaks.com/topic/102634-rankvoting-system/#findComment-526518 Share on other sites More sharing options...
deadonarrival Posted May 26, 2008 Share Posted May 26, 2008 And to get the items in order best to worst, try the following SELECT * FROM answer ORDER BY a_rank DESC; or to only select positive items SELECT * FROM answer WHERE a_rank >= 0 ORDER BY a_rank DESC; Link to comment https://forums.phpfreaks.com/topic/102634-rankvoting-system/#findComment-550107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.