回声变量和非回声似乎给出不同的结果

时间:2012-04-23 11:38:23

标签: php

不知道在哪里转,因为这对我没有意义,这是我的功能:

function setLevels($db, $last, $time, $c) {
$db->setQuery("SELECT health, energy, ammo, maxHealth, maxEnergy, maxAmmo, energy_time FROM sl_user WHERE userid = '$c'")->upit();
$res = $db->getRow();
$curr = $res['energy'];
$max = $res['maxEnergy'];
$nrgtime = $res['energy_time'];
$chunks = floor(($time - $last)/180);
if ($curr < $max) {
    if (($curr + $chunks) > $max) {
        $curr = $max;
    } else {
        $curr += $chunks;
    }

    if ($curr < $max) {
        $leftover = ($time - $last) % 180  + $nrgtime;
        echo $leftover;
        $db->setQuery("UPDATE sl_user SET energy = $curr, last_access = $time, energy_time = $leftover WHERE userid = '$c'")->upit();
    } else {
        $db->setQuery("UPDATE sl_user SET energy = $curr, last_access = ".$time.", energy_time = 0 WHERE userid = '$c'")->upit();
    }
} else {
    $db->setQuery("UPDATE sl_user SET last_access = ".$time.", energy_time = 0 WHERE userid = '$c'")->upit();
}

}

现在我的问题在这里:

if ($curr < $max) {
        $leftover = ($time - $last) % 180  + $nrgtime;
        echo $leftover;
        $db->setQuery("UPDATE sl_user SET energy = $curr, last_access = $time, energy_time = $leftover WHERE userid = '$c'")->upit();
    }

当我回显$ leftover时,它会向我显示值并将该值输入数据库,一切似乎都很好。当我删除echo $ leftover;它总是在energy_time字段中输入零。我无法回应,因为我稍后会生成XML输出。

对我来说没有意义......

0 个答案:

没有答案