KeeganWolf Posted June 11, 2009 Share Posted June 11, 2009 I have a loop thats displaying information from my mysql database, but the resulting page keeps displaying Warning: Division by zero in /home/content/........./b2_wf.php on line 56 I'm in a scenario where I can't help that these values will often be zero, and I would like to just keep the warning from showing if possible. Any ideas? Here's a sample of the code echo "<form method='post' action='pr_b2_wf.php'>"; $result = mysql_query($query) or die(mysql_error()); $content = <<<CONT <table width ="800" border="1" align="center"> <tr> <th></th> <th>Product ID</th> <th>Description</th> <th>Quantity</th> <th>Case Count</th> <th>Build2</th> </tr> CONT; while($row = mysql_fetch_array($result)){ $caseb2 = ($row['buil2'] / $row['quancase']); <--- error occurs here $caseb2 = round($caseb2, 2); $content .= <<<CON <tr> <td><input type='hidden' name='prod[$i]' value='{$row['prod']}'></td> <td>{$row['prod']}</td> <td>{$row['desc']}</td> <td>{$row['quant']}</td> <td>{$row['quancase']}</td> <td><input type='text' name='buil2[$i]' value='{$caseb2}'></td> </tr> CON; ++$i; } $content .= "</table>"; echo $content; Quote Link to comment https://forums.phpfreaks.com/topic/161827-solved-division-by-zero/ Share on other sites More sharing options...
mattal999 Posted June 11, 2009 Share Posted June 11, 2009 Just do a check: <?php // Untested Code if($row['quancase'] !== 0) { $caseb2 = ($row['buil2'] / $row['quancase']); $caseb2 = round($caseb2, 2); } else { $caseb2 = 0; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161827-solved-division-by-zero/#findComment-853817 Share on other sites More sharing options...
KeeganWolf Posted June 11, 2009 Author Share Posted June 11, 2009 Thanx mattel, you rock! I'm going to either do the check, or arrange for a specific row to never be 0 Quote Link to comment https://forums.phpfreaks.com/topic/161827-solved-division-by-zero/#findComment-853842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.