简体   繁体   English

为每15分钟错误的收入设置一个上限

[英]setting a limit to a income every 15 minutes error

ok so this file runs every 15 minutes you get a income, farming and energy bonus at those stages but I don't want them to go over the $storagecap but they don't stop and they keep adding more and more food, gold, energy to your account and never stops. 好的,这样该文件每15分钟运行一次,您在这些阶段会获得收入,农业和能源红利,但我不希望他们超过$ storagecap,但是他们不会停下来,他们会继续添加越来越多的食物,黄金,为您的帐户注入能量,永不止步。

What I am trying to do is add you income and then if your income goes over $storagecap put your gold to $storagecap but it doesnt work here is my code 我想做的是增加您的收入,然后如果您的收入超过$ storagecap,则将您的黄金转到$ storagecap,但这在我的代码中不起作用

<?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 * FROM `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 and 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."' WHERE `id`='".$user['id']."'") or     die(mysql_error());
}
?>

Seems to me that you are having some syntax problems in your overflow checks. 在我看来,您的溢出检查中存在语法问题。 for one, even if this worked they would have an amount above cap until the next 15 minute round. 一,即使这行得通,他们在下一个15分钟的回合之前仍会超出上限。 For example, let say you had 99 energy, and it added 5, you would now have 104. But the cap check would still have the old values, ie 99, and would do nothing. 例如,假设您有99能量,它加了5,现在将有104。但是上限检查仍具有旧值,即99,并且什么也不做。 Also

`gold`=`gold` '$storagecap' 

is not correct, you need to use 不正确,您需要使用

`gold`= '".$storagecap."'

But to fix the 15 minute delay the best method would be this: 但是要解决15分钟的延迟,最好的方法是:

<?php
include("functions.php");
include("storagecap.php");
connect();

$get_users = mysql_query("SELECT * FROM `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 and 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."' WHERE `id`='".$user['id']."'") or     die(mysql_error());
}
?>

Please note I have not tested this code, treat it as a rough example 请注意,我尚未测试此代码,请将其作为一个粗略的示例

EDIT: Just another note, if this query is run, returning energy of, say 99, and it have to fix this to 100, and in another query running at the same time, some energy I used. 编辑:另一个要注意的是,如果运行此查询,则返回能量,比如说99,它必须将其固定为100,并且在同时运行的另一个查询中,我使用了一些能量。 This might cause this used energy to be "given back". 这可能导致该用过的能量被“退还”。 Sorry, I can't explain it better =P Look into MySQL transactions. 抱歉,我无法更好地解释它= P查看MySQL事务。

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

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