morbid angel911 Posted December 15, 2010 Share Posted December 15, 2010 $0 [ Warning: Division by zero in /home/mintcity/public_html/v2/inc.cartel.buy.php on line 44 0] <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">$<? echo number_format($myrowcs[price]) ?> [<font size="1" face="Verdana, Arial, Helvetica" color="#FFC000"><u><? echo floor(($myrow2b[money] / $myrowcs[price])); ?></u></font>]</font></b></td> This is my code on line 44. Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 Most probably the variable $myrowcs[price] has a value of zero (0) Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 The best thing you can do to find out is to remove echo floor(($myrow2b[money] / $myrowcs[price])); and leave it like this: <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">$<? echo number_format($myrowcs[price]) ?> [<font size="1" face="Verdana, Arial, Helvetica" color="#FFC000"><u></u></font>]</font></b></td> to see what the value of that variable is Quote Link to comment Share on other sites More sharing options...
morbid angel911 Posted December 15, 2010 Author Share Posted December 15, 2010 I cannot figure out the value. I'm so stuck. Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 could you post all the code of the page? it will be much easier Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 and also if you did use the code i told you and got nothing it means that the variable is empty which means that you cannot divide by nothing (0) so that is why you get the error! try to find out why the variable gets no value or the value zero Quote Link to comment Share on other sites More sharing options...
morbid angel911 Posted December 15, 2010 Author Share Posted December 15, 2010 <? $cid = $myrow[cid]; ?> <form action="cartel.buyitems.submit.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>" method="POST" enctype="application/x-www-form-urlencoded"> <table border="0" width="100%"> <tr> <td width="10%"><p align="CENTER"><b><font size="1" face="Verdana, Arial, Helvetica">QTY</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">ITEM</font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica">DESCRIPTION</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">PRICE</font></b></td> <td width="25%"><p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica">YOU HAVE</font></b></td> </tr> <? $sql2b = "SELECT money from og_cartelinfo where id=$cid"; @mysql_connect($dbhost, $dbuser, $dbpass); @mysql_select_db($dbname) or die("Error opening database"); $result2b = @mysql_query($sql2b); $myrow2b = @mysql_fetch_array($result2b); $sqlcs = "SELECT * from og_cartelrates where buy=1 order by id"; @mysql_connect($dbhost, $dbuser, $dbpass); @mysql_select_db($dbname) or die("Error opening database"); $resultcs = @mysql_query($sqlcs); $myrowcs = @mysql_fetch_array($resultcs); do { ?> <tr> <td width="10%"> <center> <p><input type="TEXT" name="item[<? echo $myrowcs[id] ?>]" size="4" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"> </center> </td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[item_name] ?></font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[description] ?></font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">$<? echo number_format($myrowcs[price]) ?> [<font size="1" face="Verdana, Arial, Helvetica" color="#FFC000"><u><? echo floor(($myrow2b[money] / $myrowcs[price])); ?></u></font>]</font></b></td> <? $product = $myrowcs[product]; $sql2 = "SELECT $product from og_cartelinfo where id=$cid"; @mysql_connect($dbhost, $dbuser, $dbpass); @mysql_select_db($dbname) or die("Error opening database"); $result2 = @mysql_query($sql2); $myrow2 = @mysql_fetch_array($result2); ?> <td width="25%"> <p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo number_format($myrow2[$product]) ?></font></b> </td> </tr> <? } while ($myrowcs = @mysql_fetch_array($resultcs)); ?> <? if ($case) { ?> <tr> <td colspan="5"><br> <center><b><font size="2" face="Verdana, Arial, Helvetica">Whatcha doin foo? You ain't got enuff cash!</font></b></center> </td> </tr> <? } ?> <tr> <td colspan="5"><br> <br> <center><b><font size="1" face="Verdana, Arial, Helvetica">You have $<? echo number_format($myrow2b[money]) ?> to spend!</font></b></center><br><br> <input type="hidden" name="cid" value="<? echo $cid ?>"> <center><input type="submit" name="buy items" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"></center> </td> </tr> </table> </form> This is the entire code. You don't think it would have something to do with my database do you? Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 Try it now and let me now if it works so i can explain what was wrong <? $cid = $myrow[cid]; ?> <form action="cartel.buyitems.submit.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>" method="POST" enctype="application/x-www-form-urlencoded"> <table border="0" width="100%"> <tr> <td width="10%"><p align="CENTER"><b><font size="1" face="Verdana, Arial, Helvetica">QTY</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">ITEM</font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica">DESCRIPTION</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">PRICE</font></b></td> <td width="25%"><p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica">YOU HAVE</font></b></td> </tr> <? $sql2b = "SELECT `money` from `og_cartelinfo` where `id`='$cid'"; @mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to database"); @mysql_select_db($dbname) or die("Error opening database"); $result2b = @mysql_query($sql2b); $myrow2b = @mysql_fetch_array($result2b); $sqlcs = "SELECT * from `og_cartelrates` where `buy`='1' order by `id`"; $resultcs = @mysql_query($sqlcs); $myrowcs = @mysql_fetch_array($resultcs); do { ?> <tr> <td width="10%"> <center> <p><input type="TEXT" name="item[<? echo $myrowcs[id] ?>]" size="4" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"> </center> </td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[item_name] ?></font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[description] ?></font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">$<? echo number_format($myrowcs[price]) ?> [<font size="1" face="Verdana, Arial, Helvetica" color="#FFC000"><u><? echo floor(($myrow2b[money] / $myrowcs[price])); ?></u></font>]</font></b></td> <? $product = $myrowcs[product]; $sql2 = "SELECT `product` from `og_cartelinfo` where `id`='$cid'"; $result2 = @mysql_query($sql2); $myrow2 = @mysql_fetch_array($result2); ?> <td width="25%"> <p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo number_format($myrow2[$product]) ?></font></b> </td> </tr> <? } while ($myrowcs = @mysql_fetch_array($resultcs)); ?> <? if ($case) { ?> <tr> <td colspan="5"><br> <center><b><font size="2" face="Verdana, Arial, Helvetica">Whatcha doin foo? You ain't got enuff cash!</font></b></center> </td> </tr> <? } ?> <tr> <td colspan="5"><br> <br> <center><b><font size="1" face="Verdana, Arial, Helvetica">You have $<? echo number_format($myrow2b[money]) ?> to spend!</font></b></center><br><br> <input type="hidden" name="cid" value="<? echo $cid ?>"> <center><input type="submit" name="buy items" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"></center> </td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
morbid angel911 Posted December 15, 2010 Author Share Posted December 15, 2010 I tried your code and now it is saying Warning: Division by zero in /home/mintcity/public_html/v2/inc.cartel.buy.php on line 43 0] instead of online 44 Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 Try this and tell me if you get anything there <? $cid = $myrow[cid]; ?> <form action="cartel.buyitems.submit.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>" method="POST" enctype="application/x-www-form-urlencoded"> <table border="0" width="100%"> <tr> <td width="10%"><p align="CENTER"><b><font size="1" face="Verdana, Arial, Helvetica">QTY</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">ITEM</font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica">DESCRIPTION</font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">PRICE</font></b></td> <td width="25%"><p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica">YOU HAVE</font></b></td> </tr> <? $sql2b = "SELECT `money` from `og_cartelinfo` where `id`='$cid'"; @mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to database"); @mysql_select_db($dbname) or die("Error opening database"); $result2b = @mysql_query($sql2b); $myrow2b = @mysql_fetch_array($result2b); $sqlcs = "SELECT * from `og_cartelrates` where `buy`='1' order by `id`"; $resultcs = @mysql_query($sqlcs); $myrowcs = @mysql_fetch_array($resultcs); $row_num = @mysql_num_rows($resultcs); echo "NUMBER OF ROWS: ".$row_num; exit(); do { ?> <tr> <td width="10%"> <center> <p><input type="TEXT" name="item[<? echo $myrowcs[id] ?>]" size="4" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"> </center> </td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[item_name] ?></font></b></td> <td width="35%"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo $myrowcs[description] ?></font></b></td> <td width="15%"><b><font size="1" face="Verdana, Arial, Helvetica">$<? echo number_format($myrowcs[price]) ?> [<font size="1" face="Verdana, Arial, Helvetica" color="#FFC000"><u><? echo floor(($myrow2b[money] / $myrowcs[price])); ?></u></font>]</font></b></td> <? $product = $myrowcs[product]; $sql2 = "SELECT `product` from `og_cartelinfo` where `id`='$cid'"; $result2 = @mysql_query($sql2); $myrow2 = @mysql_fetch_array($result2); ?> <td width="25%"> <p align="RIGHT"><b><font size="1" face="Verdana, Arial, Helvetica"><? echo number_format($myrow2[$product]) ?></font></b> </td> </tr> <? } while ($myrowcs = @mysql_fetch_array($resultcs)); ?> <? if ($case) { ?> <tr> <td colspan="5"><br> <center><b><font size="2" face="Verdana, Arial, Helvetica">Whatcha doin foo? You ain't got enuff cash!</font></b></center> </td> </tr> <? } ?> <tr> <td colspan="5"><br> <br> <center><b><font size="1" face="Verdana, Arial, Helvetica">You have $<? echo number_format($myrow2b[money]) ?> to spend!</font></b></center><br><br> <input type="hidden" name="cid" value="<? echo $cid ?>"> <center><input type="submit" name="buy items" style="Font-Family : Verdana, Arial, Helvetica ; Font-Size : 7pt"></center> </td> </tr> </table> </form> you should get a "NUMBER OF ROWS: " and next to it a number! please tell me what that number is Quote Link to comment Share on other sites More sharing options...
morbid angel911 Posted December 15, 2010 Author Share Posted December 15, 2010 CARTEL: BUY ITEMS. NUMBER OF ROWS: 0 Quote Link to comment Share on other sites More sharing options...
solon Posted December 15, 2010 Share Posted December 15, 2010 ok then... this means that the query from which you are trying to get the price gives an empty result. try to see if you have info in that table and it is important to create a function to handle the empty result since you do mathematical operations in your script to avoid this kind of problems in the future! Quote Link to comment 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.