goatboy Posted September 20, 2006 Share Posted September 20, 2006 i've been succesfully using the 5 star rating system from phpfreaksbut i have one problem.From time to time i'll need to delete someones rating. If i do that the rate total still shows the total rating with their vote included.Does anyone know what reverse math to use so their vote is undone?here's the math that adds their rating[code]$new_count = ($num_votes + 1); $total = $rate_total * $num_votes;$total2 = (($rate + $total) / ($new_count));$new_rating3 = number_format($total2, 2, '.', '');[/code] Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/ Share on other sites More sharing options...
obsidian Posted September 20, 2006 Share Posted September 20, 2006 if you are simply storing the total number of votes and their average, there is no way to reverse it unless you have a database backup you can restore. if you are storing each individual vote in addition to the totals, you can simply delete their vote and then recalculate the total. Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95581 Share on other sites More sharing options...
goatboy Posted September 20, 2006 Author Share Posted September 20, 2006 yes, i store the individual persons vote in addition to the total in a different table for the item they are rating.I just wanted to see if there was a quicker way to do it.I think i'll just do it the way you mentioned. I also though about doing all the math on the fly and just storing the total number of votes and total rating but i don't know if thats a good idea if i have 20 rating listed on a page, that and i'd have to recalculate and change the table structure for all the votes i currently have.Thanks Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95597 Share on other sites More sharing options...
Daniel0 Posted September 20, 2006 Share Posted September 20, 2006 1. Delete the vote.2. Select everything from the table.3. Get the number of rows returned4. Set the total number of votes to what you got in number 3. Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95601 Share on other sites More sharing options...
goatboy Posted September 20, 2006 Author Share Posted September 20, 2006 besides counting the number of votes i need to add all the user ratings as well, i know i can use mysql_num_rows to count how many votes but how do i add all the ratings in the loop?[code]while(list($rating) = mysql_fetch.....{ what goes here?}[/code] Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95607 Share on other sites More sharing options...
obsidian Posted September 20, 2006 Share Posted September 20, 2006 [code]SELECT SUM(ratings) AS sum, AVG(ratings) AS avg, COUNT(ratings) AS count FROM ratings table;[/code]that query (modified as you need it, of course) will return all the values you need for a 5 star rating system. so, once you delete the errant vote, just pull those values and have at it. Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95624 Share on other sites More sharing options...
goatboy Posted September 20, 2006 Author Share Posted September 20, 2006 sweet, thats perfect.Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/21445-reversing-a-rating/#findComment-95669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.