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
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

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.