In this code I want to retrieve the energy and max energy of a players account, then add 8% to energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy. Then the database is updated.I don't understand why it's not working.
$query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1");$row = mysql_fetch_assoc($query);$id = $row['maxid']; $query = "SELECT * FROM `accounts`"; $result=mysql_query($query);while ($row=mysql_fetch_assoc($result)) {$energy = $row['energy'];$maxenergy = $row['maxenergy'];}for($i=1; $i<="$id"; $i++) {$query = "SELECT * FROM `accounts` WHERE (id) = '".$id."'";$result=mysql_query($query);$addenergy = (0.08 * $maxenergy);$energy = ($addenergy + $energy);if($energy > $maxenergy) {$energy = $maxenergy;}$query = "UPDATE `account` SET (energy) = '".$energy."' WHERE (id) = '".$id."'";$result = mysql_query($query);echo" The energy script worked!";}