Jump to content

Update query, don't go below 0?


cdoyle

Recommended Posts

Hi

I'm using this update query, to update the 'Awake' column.

 

$statupdate=($player->energy*$player->Awake)/100;
$energyreduce=($_POST['trainamount']);
$awakereduce=($player->Awake - ($_POST['trainamount'] * .4));


$updatestrength = $db->execute("UPDATE `players` SET `strength`= `strength`+?, `Awake`=?, `energy`= `energy`-? WHERE `id`=?", array($statupdate,  $awakereduce, $energyreduce, $player->id));

 

which works fine, but if a player has less 'Awake' then what $awakereduce value is,

It gives them a negative number.

How would I change this so, instead of updating the 'Awake' column with a negative number.  It just updates it to 0?

 

 

Link to comment
https://forums.phpfreaks.com/topic/121337-update-query-dont-go-below-0/
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.