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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.