Jump to content

Help with a cron job.


seany123

Recommended Posts

would this work?

 

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $awake = $row['awake'] + 5);
   $awake = ($awake > $row['maxawake']) ? $row['maxawake'] : $awake;
   $query = sprintf('UPDATE players SET awake = %d WHERE id = %d', $awake, $row['id']);
   mysql_query($query) or die(mysql_error());
}

Link to comment
Share on other sites

im looking for something like this:

 

$query = "SELECT * FROM players";

$result = mysql_query($query) OR die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {

  $energy = $row['energy'] + ($row['maxenergy'] * .25);

  $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;

  $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);

  mysql_query($query) or die(mysql_error());

}

 

i want it to add +5 instead of 25% of maxenergy... it still cant gover over maxenergy though.

Link to comment
Share on other sites

im looking for something like this:

 

$query = "SELECT * FROM players";

$result = mysql_query($query) OR die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {

   $energy = $row['energy'] + ($row['maxenergy'] * .25);

   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;

   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);

   mysql_query($query) or die(mysql_error());

}

 

i want it to add +5 instead of 25% of maxenergy... it still cant gover over maxenergy though.

Not too familiar with mysql..so bear with...

 

while ($row = mysql_fetch_assoc($result)) {

  if ($row['energy'] < $row['maxenergy']){ // Check to see if energy is less than max

      $new_energy = $row['energy'] + 5; // add 5 to energy

      if($new_energy > $row['maxenergy']){ // check to make sure energy is not more than max

        $new_energy = $row['maxenergy']; // set energy to max energy if it was previous greater than.

      }

      $query = sprintf('UPDATE players set energy = $new_energy where id = $row['id']);

      myqsql_query($query) or die(mysql_error());

  }

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.