PDA

View Full Version : Division by zero problem.


neverstop
07-24-2007, 04:33 AM
I am not a coder so I am hoping someone here can help me with a p[roblem I am having witha module for vbadvanced cmps. I added a "latest links" module and I get was trying to get a rating image to show and I get this error:
Division by zero in /modules/latestlinks.php on line 69

Line 69:
$link['truerating'] = vb_number_format($link['votetotal'] / $link['votenum'], 2);

Im sure this is an easy fix but I am not a coder. Can anyone help a brother out?

I should mention that this only happens if there is a link with no votes. If a link has a rating the error doesnt show up.

Adrian Schneider
07-24-2007, 05:46 AM
Simple... if it has no votes, then you are dividing by zero when calculating your average. Try this,

$link['truerating'] = $link['votenum'] ? vb_number_format($link['votetotal'] / $link['votenum'], 2) : 0;

neverstop
07-25-2007, 04:44 AM
Cool! That seems to have worked. Thanks a lot.