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
https://forums.phpfreaks.com/topic/124372-help-with-a-cron-job/#findComment-642326
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
https://forums.phpfreaks.com/topic/124372-help-with-a-cron-job/#findComment-642467
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
https://forums.phpfreaks.com/topic/124372-help-with-a-cron-job/#findComment-643074
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.