I made a Poll Voting with an Result Page. But wenn there are no votes it gives me an NAN Calc Error.
Code:
<div class="progress-bar" style="background-color: #38b673; width:<?= @(($poll_answer['votes'] / $total_votes) * 100)?>%">
<?= @round(($poll_answer['votes'] / $total_votes) * 100) ?>%
</div>
I tried different things, but nothing works.
Maybe anyone knows how to fix.
You can just use max()
function to overcome divide by 0 issue.
<?php echo round(($poll_answer['votes'] / max(1,$total_votes)) * 100); ?>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments