简体   繁体   English

警告:PHP 中的除以零

[英]Warning: Division by Zero in PHP

https://ctrlv.cz/c7pu https://ctrlv.cz/c7pu

The error I am receiving, I don't understand why though.我收到的错误,但我不明白为什么。 I have a feeling that it is something to deal with the $bank variable but I am quite new with PHP and I don't quite understand all of the code:我有一种感觉,这是处理 $bank 变量的事情,但我对 PHP 很陌生,我不太了解所有代码:

PHP: PHP:

<?php

  $thisgame = fetchinfo("value","info","name","current_game");
  $bank = fetchinfo("cost","games","id",$thisgame);

  $thisuserid=$rsx['uid'];

  $result = mysql_query("SELECT SUM(value) AS value FROM `game$thisgame` WHERE `userid`='$thisuserid'");
  $getrowval = mysql_fetch_assoc($result);
  $generatechance=round($getrowval["value"]*100/$bank,1);
  $howmanyitems=mysql_num_rows(mysql_query('SELECT * FROM `game'.$thisgame.'` WHERE   `userid`="'.$thisuserid.'"'));

  $profilele='http://steamcommunity.com/profiles/'.$thisuserid;
?>

Those are lines 77 to 90 so.... Anyone have an idea?那些是第 77 行到第 90 行,所以……有人知道吗?

replace $generatechance=round($getrowval["value"]*100/$bank,1);替换$generatechance=round($getrowval["value"]*100/$bank,1); with and let me know if it works并让我知道它是否有效

if( $bank > 0 ){
    $generatechance=round($getrowval["value"]*100/$bank,1);
}else{
    $generatechance = <YOU NEED TO DO THIS PART>
}

more better idea will be $bank = fetchinfo("cost","games","id",$thisgame);更好的主意是$bank = fetchinfo("cost","games","id",$thisgame); after this line check if you are getting $bank or not.在此行之后检查您是否收到 $bank。

check if $result = mysql_query("SELECT SUM(value) AS value FROM game$thisgame WHERE userid ='$thisuserid'");检查是否$result = mysql_query("SELECT SUM(value) AS value FROM game$thisgame WHERE userid ='$thisuserid'"); query is correct game$thisgame .查询是正确的game$thisgame

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM