user1778755
user1778755

Reputation: 11

How do i get rid of the division by zero php error in this plugin?

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

Answers (3)

HVKotak
HVKotak

Reputation: 258

($cb_point_entry_limit > 0) ? round(($cp_point_entry_results / $cb_point_entry_limit) * 100) : 0

Upvotes: 0

air4x
air4x

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

Matt Ball
Matt Ball

Reputation: 359856

Don't perform the calculation when $cb_point_entry_limit is zero.

Upvotes: 1

Related Questions