Jump to content

[SOLVED] php script help edit please


Jiraiya

Recommended Posts

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.