seany123 Posted October 6, 2008 Share Posted October 6, 2008 okay well because my host doesn't support cron jobs im doing it so a page runs every so often and it updates certain database entries. only thing is im wanting to change it now so if the person's ($player->rm = 1) then it updates the database for them differently. but im not too good at php and need a little help. Ive already attempted what i want doing... <?php if(!defined('IN_GAME')) die('HACK'); if ($player->rm >= 1) { $query = $db->execute("update `players` set awake = IF((awake + 10)>maxawake, maxawake, (awake + 10))" ); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $energy = $row['energy'] + ($row['maxenergy'] * .20); $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy; $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']); mysql_query($query) or die(mysql_error()); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $nerve = $row['nerve'] + ($row['maxnerve'] * .20); $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve; $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']); mysql_query($query) or die(mysql_error()); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $hp = $row['hp'] + ($row['maxhp'] * .25); $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp; $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']); mysql_query($query) or die(mysql_error()); } $query = $db->execute("update `players` set awake = IF((awake + 5)>maxawake, maxawake, (awake + 5))" ); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $energy = $row['energy'] + ($row['maxenergy'] * .10); $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy; $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']); mysql_query($query) or die(mysql_error()); } $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $nerve = $row['nerve'] + ($row['maxnerve'] * .10); $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve; $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']); mysql_query($query) or die(mysql_error()); } $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $hp = $row['hp'] + ($row['maxhp'] * .25); $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp; $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']); mysql_query($query) or die(mysql_error()); } ?> I didn't get a error using this script... but it wouldn't go onto my website (which must show a bad sign ) Above ive only done 1 if for all 4 queries, but do i need to do a new if for each? Also the very first query does the same if rm = 1 or 0 so do i do it, with a if then without a if? or just without? maybe im getting you confused but im sure you can see what i mean. thanks. ~seany Link to comment https://forums.phpfreaks.com/topic/127318-help-with-ifs/ Share on other sites More sharing options...
fanfavorite Posted October 7, 2008 Share Posted October 7, 2008 First thing I noticed is that the first two while statements and the if statement is not closed with a "}". You should have received an error. If you are using IE, make sure you uncheck "show friendly http errors" in the internet options. As for the $player->rm, should this be $player->$rm? What is $player->rm supposed to do? Link to comment https://forums.phpfreaks.com/topic/127318-help-with-ifs/#findComment-658722 Share on other sites More sharing options...
nrg_alpha Posted October 7, 2008 Share Posted October 7, 2008 Not only is the first two while statements missing closing curly braces.. I don't think I can see the closing brace for the second if statement either. I would endure that you have error reporting turned on. Just by this code alone, there are some proper nesting issues. You can use: error_reporting(E_ALL); or: ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); You really need to format your code carefully and ensure that your have the proper matching curly braces. Link to comment https://forums.phpfreaks.com/topic/127318-help-with-ifs/#findComment-658730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.