cdoyle Posted August 26, 2008 Share Posted August 26, 2008 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 More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Do a check before the query. It would look something like: $awakereduce = ($awakereduce < 0) ? 0 : $awakereduce; Link to comment https://forums.phpfreaks.com/topic/121337-update-query-dont-go-below-0/#findComment-625591 Share on other sites More sharing options...
cdoyle Posted August 26, 2008 Author Share Posted August 26, 2008 Do a check before the query. It would look something like: $awakereduce = ($awakereduce < 0) ? 0 : $awakereduce; Thanks, that worked great! Link to comment https://forums.phpfreaks.com/topic/121337-update-query-dont-go-below-0/#findComment-625604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.