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.
max()
<?php echo round(($poll_answer['votes'] / max(1,$total_votes)) * 100); ?>
2.1m questions
2.1m answers
60 comments
57.0k users