Jiraiya Posted December 26, 2008 Share Posted December 26, 2008 i need help editing my script to make it work with a cron, i need it to update every players variable even if the player is not logged on function UpdateHealthBar($player){ if($player != ''){ $sql = mysql_query("SELECT `username`,`max_health`, `health`, `last_update` FROM `users` WHERE `username` = '$player'") or die(mysql_error()); $user = mysql_fetch_assoc($sql) or die(mysql_error()); // vars $username = $user['username']; $user_health = $user['health']; $max_health = $user['max_health']; mysql_query("UPDATE `users` SET `health` = '$max_health', `last_update` = '$last_update' WHERE `username` = '$player'") or die(mysql_error()); } } } UpdateHealthBar($player); Link to comment https://forums.phpfreaks.com/topic/138425-solved-php-script-help-edit-please/ Share on other sites More sharing options...
ratcateme Posted December 26, 2008 Share Posted December 26, 2008 so do you just want to set everys players health to max_health? this would do it i think UPDATE `users` SET `health` = `max_health` or if you want to set the last_update to the time UPDATE `users` SET `health` = `max_health` `last_update` = NOW() the script would look like this <?php //include connection mysql_query("UPDATER `users` SET `health` = `max_health` `last_update` = NOW()") or die(mysql_error()); ?> Scott. Link to comment https://forums.phpfreaks.com/topic/138425-solved-php-script-help-edit-please/#findComment-723770 Share on other sites More sharing options...
Jiraiya Posted December 26, 2008 Author Share Posted December 26, 2008 yea i want to set every players health to max_health Link to comment https://forums.phpfreaks.com/topic/138425-solved-php-script-help-edit-please/#findComment-723778 Share on other sites More sharing options...
Jiraiya Posted December 26, 2008 Author Share Posted December 26, 2008 im confused with the script for this can someone please help? Link to comment https://forums.phpfreaks.com/topic/138425-solved-php-script-help-edit-please/#findComment-723820 Share on other sites More sharing options...
chronister Posted December 26, 2008 Share Posted December 26, 2008 Take a look at the following page and see if it clears anything up for you. http://htmlcenter.com/blog/running-php-scripts-with-cron/ One issues i see is that your passing the $player variable into the function that is going to do the update. Since CRON is completely automated, you will need to get a list of the players and then pass the info into the function. The script ratcateme gave ya would do it a little bit easier. It looks like it will set columnA to the value of columnB. I am not sure how this works if players have a different max_health number, but you could certainly duplicate this table to a test table and run the code ratcateme gave you and see if it does what you want. Otherwise, you would basically take what you have and use that, but still look at the site I gave a link to as it explains the 2 different methods for running a php script as a CRON job. Nate Link to comment https://forums.phpfreaks.com/topic/138425-solved-php-script-help-edit-please/#findComment-723874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.