phpbeginner Posted October 11, 2009 Share Posted October 11, 2009 How can I fix a division by zero error if value is null or O ? On my select statements above this code, I tried to only get values if field is not null but I still can't resolve the issue. First 2 lines ($savep and $gaa) give the errors if value is NULL $savep = number_format ($saves / $shots, 3, '.', ''); $gaa = number_format ($diff * (60/$min), 2, '.', ''); if($class=='text') $class=''; else $class='text'; echo "<tr> <td class='$class' >$r[pnumber]</td> <td class='$class' ><a href='player.php?tid=1&pid=$r[pid]'>$r[pfname] $r[plname]</a></td> <td class='$class' align=center>$gplayed</td> <td class='$class' align=center>$shots</td> <td class='$class' align=center>$saves</td> <td class='$class' >$savep</td> <td class='$class' >$gaa</td> </tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/177327-solved-division-by-zero/ Share on other sites More sharing options...
Mark Baker Posted October 11, 2009 Share Posted October 11, 2009 if ($shots == 0) { $savep = 0; } else { $savep = number_format ($saves / $shots, 3, '.', ''); } and the equivalent for your other calculation Quote Link to comment https://forums.phpfreaks.com/topic/177327-solved-division-by-zero/#findComment-934987 Share on other sites More sharing options...
phpbeginner Posted October 11, 2009 Author Share Posted October 11, 2009 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/177327-solved-division-by-zero/#findComment-934991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.