warning: Division by zero in sites\all\modules\fivestar\fivestar_field.inc on line 297.
demon326 - July 26, 2009 - 11:13
| Project: | Fivestar |
| Version: | 6.x-1.18 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
When i set the output to percentage i'l get this error when viewing the node;
warning: Division by zero in C:\wamp\www\ashladan2\sites\all\modules\fivestar\fivestar_field.inc on line 297.don't think this is good :)

#1
I've got exactly the same problem. Any ideas?
line 297 is "}"...
#2
We can't do any of the calculations without both the rating and # of stars values, so we should probably return 0. Does this patch help?
#3
ezra-g, can you make a simple find an replace for non coder users? thx!
#4
@demon326 -- Check out http://drupal.org/node/323498 for instructions on applying a patch ;). It's not too hard :).
#5
ezra-g, it's not working.. you also forget to add a "}" after the
return round(100/$element['#item']['rating'], 1)/$element['#field']['stars'];line, and it stays saying that the above line is the problem..the full code block:
/* * Theme function for 'percentage' fivestar field formatter.
*/
function theme_fivestar_formatter_percentage($element) {
if (empty($element['#item']['rating']) || empty($element['#item']['stars'])) {
return 0;
}
return round(100/$element['#item']['rating'], 1)/$element['#field']['stars'];
}
#6
@demon326: Did you actually apply and review this patch? It resolves the issue for me, and there is no missing bracket in the code once it is applied.
#7
Turns out this needed a slight change - to check for empty($element['#field']['stars']) instead of empty($element['#item']['stars'])) .
#8
This is now committed.
#9
This bug also showed up for me on the search results page when a fivestar-enabled content type was included in the results
however, in my testing on the search results page, the '$element['#field']['stars']' is always empty but '$element['#item']['stars']' always has a value
are there cases where '$element['#field']['stars']' has a value?
maybe if the function is entered in some other page other than search results?
#10
Are you getting this error on the same line as reported in this issue, with the latest dev release?
#11
Automatically closed -- issue fixed for 2 weeks with no activity.