警告:在PHP中除以零

时间:2015-11-28 02:45:10

标签: php warnings division zero

https://ctrlv.cz/c7pu

我收到的错误,我不明白为什么。我有一种感觉,它是处理$ bank变量的东西,但我对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;
?>

那些是第77到90行所以....任何人都有想法?

1 个答案:

答案 0 :(得分:0)

替换$generatechance=round($getrowval["value"]*100/$bank,1);并让我知道它是否有效

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

更好的想法是$bank = fetchinfo("cost","games","id",$thisgame);在此行检查之后是否获得$ bank。

检查$result = mysql_query("SELECT SUM(value) AS value FROM游戏$ thisgame WHERE userid ='$thisuserid'");查询是否正确game$thisgame