Jump to content

Need Help with update query


cdoyle

Recommended Posts

Hi,

 

I have a update query, that is run with a cron every 15 minutes.

 

$query = $db->execute("update `players` set hp = hp + 10" );

 

What it does is increases a players hp 10 every 15 minutes. 

this part is working good, but here is the problem.

 

Depending on the level a player is, they have a maxhp (there is a field name in the players table called maxhp)

 

How can I make it so it updates up to the maxhp and then stop?  Right now, it just keeps going and going and going (lol)

 

 

Link to comment
https://forums.phpfreaks.com/topic/96553-need-help-with-update-query/
Share on other sites

you could query the players first. I don't know your query functions so will use basic php

<?php
$query = "SELECT `hp, `maxhp` FROM `players`";
$result = mysql_query($query) or die(mysql_error());
while($r = mysql_fetch_assoc($result)){
  if($r['hp'] < $r['maxhp']){
  mysql_query("UPDATE `players` SET `hp` = `hp` + 10");
  }
}

 

Ray

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.