Skip to content

Commit

Permalink
fix division by zero because db object returns string type
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 18, 2024
1 parent 7d38dfa commit 64b9b8f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/views/dashboard-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
<button type="submit" class="button button-secondary"><?php esc_html_e('Submit', 'koko-analytics'); ?></button>
</div>
</div>
</div>
</form>
</form>
</div>
</div>

<div class="ka-page-filter" <?php echo $page === 0 ? 'style="display: none;"' : ''; ?>>
Expand All @@ -99,7 +99,7 @@
<?php
/* Total visitors */
$diff = $totals->visitors - $totals_previous->visitors;
$change = $totals_previous->visitors === 0 ? 0 : $totals->visitors / $totals_previous->visitors - 1;
$change = $totals_previous->visitors == 0 ? 0 : ($totals->visitors / $totals_previous->visitors) - 1;
?>
<tr class="<?php echo $diff > 0 ? 'ka-up' : ''; ?> <?php echo $diff < 0 ? 'ka-down' : ''; ?>">
<th><?php echo esc_html__('Total visitors', 'koko-analytics'); ?></th>
Expand All @@ -124,7 +124,7 @@
<?php
/* Total pageviews */
$diff = $totals->pageviews - $totals_previous->pageviews;
$change = $totals_previous->pageviews === 0 ? 0 : $totals->pageviews / $totals_previous->pageviews - 1;
$change = $totals_previous->pageviews == 0 ? 0 : ($totals->pageviews / $totals_previous->pageviews) - 1;
?>
<tr class="<?php echo $diff > 0 ? 'ka-up' : ''; ?> <?php echo $diff < 0 ? 'ka-down' : ''; ?>">
<th><?php echo esc_html__('Total pageviews', 'koko-analytics'); ?></th>
Expand Down

0 comments on commit 64b9b8f

Please sign in to comment.