I have this code, I want it to increase the 'users' hp by 5 while keeping their hp below 'maxhp'; Currently it doesn't work, can anyone fix the code below or give me a completely different way to do it? mysql_query("UPDATE Zombie SET `Hp` = `Hp` + '5'"); $result = mysql_query("SELECT * FROM `Zombie`"); while($row = mysql_fetch_array($result)) { if ($row['Hp'] >= $row['Maxhp']) { $row['Hp'] = $row['Maxhp']; } $test = $row['Hp']; echo $row['Maxhp']; mysql_query("UPDATE Zombie SET `Hp` = '$test'"); } I don't mind how -as long as it works, Thanks alot, James
UPDATE Zombie SET Hp = if(Hp + 5 > maxhp, maxhp, Hp + 5) Code (markup): Above query considers maxhp as another column in table, if it is not the case, replace it with php variable and its done