warning: Division by zero in /MY_PATH/sites/all/modules/fivestar/fivestar.module on line 1235.

I get this error when i edit the content type settings...

Installed 5.6 with fresh voting api and fivestar 1.11 beta3, jquery update

The voting widgets on /admin/settings/fivestar are not shown at all. only selects show up.

Comments

quicksketch’s picture

I can't reproduce this issue. Perhaps it was corrected elsewhere or I need more information to reproduce. Are you using fivestar with CCK or is this just for the normal node voting?

mrgoltra’s picture

Same here. Everytime I edit any content type. I get the following error.

Using 5.7 and latest release 5.x-1.11-beta4 , voting API 5.x-1.5

* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1250.
* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1251.
* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1250.
* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1251.
* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1250.
* warning: Division by zero in /hsphere/local/home/mysite.com/sites/all/modules/voting/fivestar/fivestar.module on line 1251.

quicksketch’s picture

Status: Active » Postponed (maintainer needs more info)

Shoot, I updated my sandbox to 5.7 and matched my install to mrgoltra's, but I still can't see this problem. The mostly likely culprit looks like the 'fivestar_stars_[nodetype]' variable is set to 0. I'm not really sure how this could happen though.

To verify this is the case in beta4, could one of you try out changing line 809 to 'stars' => 5, and see if the warning goes away?. I can't figure out why this wouldn't be set to the default.

2c’s picture

quicksketch, I recently updated fivestar to version 5.x.1.11 and received the errors reported in this issue. I tried out your suggestion but it hasn't had any effect on the errors.

Bo Kleve’s picture

Version: 6.x-1.11-beta3 » 6.x-1.12

I have had the same problem with my installation.

The problem is something wrong with line 1317 that reads: $numeric_rating = $rating/(100/$stars);. Evidently $stars somehow is set to 0 somewhere before theme_fivestar_static is called?

Changing the offending line to $numeric_rating = $rating * $stars / 100; takes away any possibility of a divide by zero.

If you have the same problem on other lines, I suggest changing them accordingly. And for ease of returning to the original code, should something go wrong, just comment out the problematic line and add the changed line.

ken69’s picture

warning: Division by zero in .... fivestar/fivestar_field.inc on line 284.

284 line is:
return round(100/$element['#item']['rating'], 1)/$element['#field']['stars'];

I have % not stars and i use CCK.

Regards

quicksketch’s picture

Priority: Critical » Normal
Status: Postponed (maintainer needs more info) » Fixed

To simply ensure that we never get a division by 0 error, I've added the following code.

  if (empty($item['rating'])) {
    $item['rating'] = 0;
  }
  if (empty($field['stars'])) {
    $field['stars'] = 5;
  }

Please try out the latest version of Fivestar and reopen if this issue is not fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

aric koenig’s picture

In which file and on what line did you place this code?