Jump to content

Updating DB info


LOUDMOUTH

Recommended Posts

I have the following code to update a players attributes on a game.  right now it updates Awake and Nerve and Energy + HP in Different amounts.  I am trying to make it update all attributes 25% each time instead. 

 

Can anyone help me convert the below PHP to refill 25% each update instead of the current amounts I have?

 

$result = mysql_query("SELECT * FROM `5150players`");

while($line = mysql_fetch_assoc($result)) {

	$updated_user = new User($line['id']);

	if ($updated_user->rmdays > 0) {

		$multiplier = 2;

	} else {

		$multiplier = 1;

	}

	$username = $updated_user->username;

	$newawake = $updated_user->awake + (5 * $num_updated) * $multiplier;

	$newawake = ($newawake > $updated_user->maxawake) ? $updated_user->maxawake : $newawake;

	$newhp = $updated_user->hp + (100 * $num_updated) * $multiplier;

	$newhp = ($newhp > $updated_user->maxhp) ? $updated_user->maxhp : $newhp;

	$newenergy = $updated_user->energy + (25 * $num_updated) * $multiplier;

	$newenergy = ($newenergy > $updated_user->maxenergy) ? $updated_user->maxenergy : $newenergy;

	$newnerve = $updated_user->nerve + (25 * $num_updated) * $multiplier;

	$newnerve = ($newnerve > $updated_user->maxnerve) ? $updated_user->maxnerve : $newnerve;

	$result2 = mysql_query("UPDATE `5150players` SET `awake` = '".$newawake."', `energy` = '".$newenergy."', `nerve` = '".$newnerve."', `hp` = '".$newhp."' WHERE `username` = '".$username."'");

}

Link to comment
https://forums.phpfreaks.com/topic/171458-updating-db-info/
Share on other sites

This is simple math =)

 

Let's say I have the variable 10.

I'd write it like this

 

$num=10;

 

Now I want to increase the value of that variable by 25%.

 

All I need to do is multiply the variable with 1.25, which is +25%.

 

The code would look like this:

$num=10;
$num*=1.25;
echo $num;

 

The output would be 12.5, because 0.25(25%) out of 10 is 2.5, and + the 1 (100%), it becomes 12.5.

 

Hope this helped =)

 

Best wishes

//AngelicS

Link to comment
https://forums.phpfreaks.com/topic/171458-updating-db-info/#findComment-904371
Share on other sites

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.