Jump to content

Cron not working for some reason...


katarra

Recommended Posts

I've developed a cron that will allow someone to gain back some playing stats, but for some reason, it doesn't appear to be working.

 

$query = $db->execute("select * from `users` where `state`='rest'");
while($row = $query->fetchrow()){
    if($row['energy'] > $row['maxenergy'] && $row['hp'] > $row['maxhp'] && $row['mp'] > $row['maxmp'])
    {
         $query = $db->execute("update `users` set `energy`=?, `hp`=?, `mp`=?,`state`='getup' where `id`=?", array($row['maxenergy'], $row['maxhp'], $row['maxmp'], $row['id'])) or trigger_error(mysql_error());
         if($query){
         $query = $db->execute("select * from `users` where `state`='rest'");
         $row = $query->fetchrow();
             $msg = $row['chat']."<b>You have max HP, Energy and MP. Your state is- Getup</b><br>";
             $query = $db->execute("update `users` set `chat`=? where `id`=?", array($msg, $row['id'])) or trigger_error(mysql_error());
         }
    }
    else
    {
      //  $query = $db->execute("update `users` set `hp`=?, `mp`=?, `energy`=? where `id`=?",array($row['hp'] + 3, $row['mp'] + 3, $row['energy'] + 3, $row['id'])) or trigger_error(mysql_error());
$query = $db->execute("update `users` set `hp` = IF((hp + (maxhp + 3))<maxhp, (hp + (maxhp + 3)), maxhp)" where `id`=?",array($row['id]))  or trigger_error(mysql_error());
$query = $db->execute("update `users` set `mp` = IF((mp + (maxmp + 3))<maxmp, (mp + (maxmp + 3)), maxmp)" where `id`=?",array($row['id]))  or trigger_error(mysql_error());
$query = $db->execute("update `users` set `energy` = IF((energy + (maxenergy + 3))<maxenergy, (energy + (maxenergy + 3)), maxenergy) where `id`=?",array($row['id]))  or trigger_error(mysql_error());
        if($query){
         $query = $db->execute("select * from `users` where `state`='rest'");
         $row = $query->fetchrow();
             $msg = "".$row['chat']."<b><center>You have ".$row['hp']." / ".$row['maxhp']." HP, ".$row['energy']." / ".$row['maxenergy']." Energy, and ".$row['mp']." / ".$row['maxmp']." MP.</center></b><br>";
             $query = $db->execute("update `users` set `chat`=? where `id`=?", array($msg, $row['id']));
        }
    }
}

Link to comment
https://forums.phpfreaks.com/topic/198668-cron-not-working-for-some-reason/
Share on other sites

$query = $db->execute("update `users` set `hp` = IF((hp + (maxhp + 3))<maxhp, (hp + (maxhp + 3)), maxhp)" where `id`=?",array($row['id']))  or trigger_error(mysql_error());

 

if hp + (maxhp + 3) is smaller than maxhp

Thats like.. hp + maxhp, that'll never be smaller than maxhp. There for, it'll always return false?

, (hp + (maxhp + 3)), maxhp

I'm not quite sure what you are trying to achieve. (I'm not sure what the comma respresents in the whole statement really.. )

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.