seany123 Posted March 25, 2009 Share Posted March 25, 2009 okay so i am trying to make a page which updates the database for each player depending on their individual values. the problem im getting is its only updating the first player who runs a page which this includes. heres there code... <?php include("../lib.php"); $player = check_user($secret_key, $db); // Values for Respected mobsters. $maxinterest = 900000; $interest = ($player->bank * 0.06); //Values for normal mobsters $maxinterest2 = 300000; $interest2 = ($player->bank * 0.03); if($player->rm >= 1) { if ($interest > $maxinterest && $player->bank + $maxinterest <= $player->maxbank) { $query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $maxinterest, $player->id )); } if ($interest > $maxinterest && $player->bank + $maxinterest > $player->maxbank) { $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $maxinterest, $player->id )); } if ($interest <= $maxinterest && $player->bank + $interest <= $player->maxbank) { $query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $interest, $player->id )); } if ($interest <= $maxinterest && $player->bank + $interest > $player->maxbank) { $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $interest, $player->id )); } } if ($player->rm <= 0) { if ($interest > $maxinterest2 && $player->bank + $maxinterest2 <= $player->maxbank) { $query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $maxinterest2, $player->id )); } if ($interest > $maxinterest2 && $player->bank + $maxinterest2 > $player->maxbank) { $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $maxinterest2, $player->id )); } if ($interest <= $maxinterest2 && $player->bank + $interest2 <= $player->maxbank) { $query = $db->execute("update `players` set `bank`=? where `id`=?", array($player->bank + $interest2, $player->id )); } if ($interest <= $maxinterest2 && $player->bank + $interest2 > $player->maxbank) { $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money + $interest2, $player->id )); } } Quote Link to comment Share on other sites More sharing options...
trq Posted March 25, 2009 Share Posted March 25, 2009 i have done it all except the queries that im using only update the first player who runs a page which this is includes.... Sorry but that sentence makes little sense. Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 25, 2009 Author Share Posted March 25, 2009 yeah i agree. changed it. Quote Link to comment Share on other sites More sharing options...
trq Posted March 25, 2009 Share Posted March 25, 2009 What happens wehn a second player executes this code? And what does this have to do with cron? Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 25, 2009 Author Share Posted March 25, 2009 This page is the cron... its set to execute every X amount of time... if someone else try to execute the code it wont work because the time has been reset. (know what im saying). Quote Link to comment Share on other sites More sharing options...
trq Posted March 25, 2009 Share Posted March 25, 2009 If this script is a cron job it should not be within any web accessible directory. Users should not be able to manually execute your cron scripts. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 25, 2009 Share Posted March 25, 2009 I agree. When you set up a cron job you set the absolute path relative to the server, not the internet (did I explain that correctly? ) Just move the cron job outside of "public_html" or whatever folder it's in back into it's own folder that users can't access from the WWW. That way you can get your cron job running safely knowing users can't access it. Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 25, 2009 Author Share Posted March 25, 2009 yes i can deal with that when the page has been complete... but currently its only updateing 1 player and noone else. Quote Link to comment Share on other sites More sharing options...
trq Posted March 25, 2009 Share Posted March 25, 2009 Because all your queries contain WHERE clauses. How exactly do you expect multiple users to be updated? What does $player->id contain? Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 26, 2009 Author Share Posted March 26, 2009 here is a problem im having.... $query = sprintf('UPDATE players SET rm = %d WHERE id = %d', $rm, $row['id']); mysql_query($query) or die(mysql_error()); how do i change this so instead of it saying (rm =) it says (rm +) can anyone help me? Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 27, 2009 Author Share Posted March 27, 2009 okay so i have done what i can and this is what ive come up with... its giving my website a whitepage which obviously means somethings not quite right... please help with what you can. heres the code... <?php $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $rm = $row['rm']; $bank = $row['bank']; $maxbank = $row['maxbank']; $money = $row['money']; // Values for Respected mobsters. $maxinterest = 900000; $interest = ($row['bank'] * 0.06); //Calculations for Respected mobsters. $calc1 = $row['bank'] + $maxinterest; $calc2 = $row['money'] + $maxinterest; $calc3 = $row['bank'] + $interest; $calc4 = $row['money'] + $interest; //Values for normal mobsters. $maxinterest2 = 300000; $interest2 = ($bank * 0.03); //Calculations for Respected mobsters. $calc5 = $row['bank'] + $maxinterest2; $calc6 = $row['money'] + $maxinterest2; $calc7 = $row['bank'] + $interest2; $calc8 = $row['money'] + $interest2; if($rm >= 1) { if($interest > $maxinterest && $row['bank'] + $maxinterest <= $maxbank) { $query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc1, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest > $maxinterest && $row['bank'] + $maxinterest > $maxbank) { $query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc2, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest <= $maxinterest && $row['bank'] + $interest <= $maxbank) { $query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc3, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest <= $maxinterest && $row['bank'] + $interest > $maxbank) { $query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc4, $row['id']); mysql_query($query) or die(mysql_error()); } } if($rm <= 0) { if($interest2 > $maxinterest2 && $row['bank'] + $maxinterest2 <= $maxbank) { $query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc5, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest2 > $maxinterest2 && $row['bank'] + $maxinterest2 > $maxbank) { $query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc6, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest2 <= $maxinterest2 && $row['bank'] + $interest2 <= $maxbank) { $query = sprintf('UPDATE players SET bank = %d WHERE id = %d', $calc7, $row['id']); mysql_query($query) or die(mysql_error()); } if($interest2 <= $maxinterest2 && $row['bank'] + $interest2 > $maxbank) { $query = sprintf('UPDATE players SET money = %d WHERE id = %d', $calc8, $row['id']); mysql_query($query) or die(mysql_error()); } } } ?> EDIT: just realised i missed a }... so now its got rid of the whitepage.... now seeing if the code actaully works. Quote Link to comment Share on other sites More sharing options...
seany123 Posted March 27, 2009 Author Share Posted March 27, 2009 problem solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.