$time_current = time();
$User = $con->query("SELECT * FROM players WHERE Username='".$_SESSION['Username']."'");
$UserInfo = $User->fetch_object();
if($UserInfo->Wood == "") {
$con->query("UPDATE players SET Wood='100'");
} elseif($UserInfo->Stone == "") {
$con->query("UPDATE players SET Stone='100'");
} elseif($UserInfo->Gold == "") {
$con->query("UPDATE players SET Gold='100'");
}
if((time() - $UserInfo->LastGivenWood) >= 10) {
$wood_to_give = 20;
$time = 10;
$last_given = $UserInfo->LastGivenWood;
$added_wood = ceil(($time_current-$last_given )/$time) * $wood_to_give;
echo $added_wood."<br>";
echo $last_given."<br>";
echo $time."<br>";
echo $wood_to_give."<br>";
$con->query("UPDATE players SET Wood=Wood+$added_wood WHERE Username='". $_SESSION['Username']."'");
}
if((time() - $UserInfo->LastGivenStone) >= 10) {
$stone_to_give = 20;
$time = 10;
$last_given = $UserInfo->LastGivenStone;
$added_stone = ceil(($time_current-$last_given)/$time) * $stone_to_give;
$con->query("UPDATE players SET Stone=Stone+$added_stone WHERE Username='". $_SESSION['Username']."'");
}
if (isset($added_wood) && $added_wood>0) $con->query("UPDATE players SET LastGivenWood=$time_current WHERE Username='".$_SESSION['Username']."'");
if (isset($added_stone) && $added_stone>0) $con->query("UPDATE players SET LastGivenStone=$time_current WHERE Username='".$_SESSION['Username']."'");
由于一些非常奇怪的原因,$added_stone
这是一个类似于2,757,953,800
第一次提供资源的数字(在用户第一次登录之后)我在第一次收到资源后尝试再次回显它。第二次是应该的(20)
所以我所有的资源都设置为一个类似于的数字2,757,953,800
,有谁知道如何解决这个问题
编辑:另外,$last_given
我的意思是(他们都表现得一样)对不起。$added_wood
$added_stone