mingkus 0 Report post Posted August 21, 2008 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!";} Share this post Link to post Share on other sites
Feelay 0 Report post Posted August 21, 2008 (edited) maybe if you tell us what error messages you get. it would be easier for us to help you ? EDIT: I THINK that you can't make the energy get higher, or? well, if thats your problem, you should try to add this: $energy = ($addenergy += $energy); If thats the fault, then that should be the solution. And remember to write what your problem is, and NOT ONLY what you want to accomplish. because we can hardly guess what your problem is. And another thing the "the energy script worked" echo, wont work as you think. it will execute whatever happens, becuse you have no if statement Edited August 21, 2008 by Feelay (see edit history) Share this post Link to post Share on other sites
wutske 0 Report post Posted August 21, 2008 A very usefull trick to debug sql query is to add 'or die(mysql_error())' after every query you make, this way your script will stop once SQL throws an error and the error will be shown to you.eg. $result = mysql_query($query) or die(mysql_error()); Another usefull trick is to echo variables so you can actualy see their values instead of guessing and hoping. Share this post Link to post Share on other sites