php - setting a limit to a income every 15 minutes error -
ok file runs every 15 minutes income, farming , energy bonus @ stages don't want them go on $storagecap don't stop , keep adding more , more food, gold, energy account , never stops.
what trying add income , if income goes on $storagecap put gold $storagecap doesnt work here code
<?php include("functions.php"); connect(); include("user_stats.php"); ?> <?php if(isset($_session['uid'])){ include("safe.php"); include("storagecap.php");?> <?php $get_users = mysql_query("select * `stats`") or die(mysql_error()); while($user = mysql_fetch_assoc($get_users)) { //get $gold = $user["gold"]; $food = $user["food"]; $energy = $user["energy"]; //increment $gold += $user["income"]; $food += $user["farming"]; $energy += 5; //verify , correct if($energy > 100) $energy = 100; if($gold > $storagecap) $gold = $storagecap; if($food > $storagecap) $food = $storagecap; //submit $update = mysql_query("update `stats` set `gold`= '".$gold."', `food`= '".$food."', `energy`= '".$energy."' `id`='".$user['id']."'") or die(mysql_error()); } ?>
seems me having syntax problems in overflow checks. one, if worked have amount above cap until next 15 minute round. example, let had 99 energy, , added 5, have 104. cap check still have old values, i.e. 99, , nothing.
`gold`=`gold` '$storagecap'
is not correct, need use
`gold`= '".$storagecap."'
but fix 15 minute delay best method this:
<?php include("functions.php"); include("storagecap.php"); connect(); $get_users = mysql_query("select * `stats`") or die(mysql_error()); while($user = mysql_fetch_assoc($get_users)) { //get $gold = $user["gold"]; $food = $user["food"]; $energy = $user["energy"]; //increment $gold += $user["income"]; $food += $user["farming"]; $energy += 5; //verify , correct if($energy > 100) $energy = 100; if($gold > $storagecap) $gold = $storagecap; if($food > $storagecap) $food = $storagecap; //submit $update = mysql_query("update `stats` set `gold`= '".$gold."', `food`= '".$food."', `energy`= '".$energy."' `id`='".$user['id']."'") or die(mysql_error()); } ?>
please note have not tested code, treat rough example
edit: note, if query run, returning energy of, 99, , have fix 100, , in query running @ same time, energy used. might cause used energy "given back". sorry, can't explain better =p mysql transactions.
Comments
Post a Comment