Reputation: 11
How do I get rid of the division by zero php warning in this plugin ?
Warning: Division by zero in /home/fortduby/public_html/wp-content/plugins/cp_giveaway_n_bets/shortcodes/lottery1.php on line 472
$cb_lottery_point_entries_left = round(($cp_point_entry_results / $cb_point_entry_limit) * 100);
Upvotes: 0
Views: 217
Reputation: 258
($cb_point_entry_limit > 0) ? round(($cp_point_entry_results / $cb_point_entry_limit) * 100) : 0
Upvotes: 0
Reputation: 5683
Change it to whichever makes sense of these two in your case
$cb_lottery_point_entries_left = 0;
if ($cb_point_entry_limit != 0) {
$cb_lottery_point_entries_left = round(($cp_point_entry_results / $cb_point_entry_limit) * 100);
}
Or
if ($cb_point_entry_limit != 0) {
$cb_lottery_point_entries_left = round(($cp_point_entry_results / $cb_point_entry_limit) * 100);
} else {
$cb_lottery_point_entries_left = $cp_point_entry_results;
}
Upvotes: 0
Reputation: 359856
Don't perform the calculation when $cb_point_entry_limit
is zero.
Upvotes: 1