Page 1 of 1

updating to many things.. help please =)

Posted: Mon Dec 13, 2010 5:42 am
by zvi5

Code: Select all

<?php
$playerinfo ="select * from players where name = '$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$pattackers = $playerinfo3['attack'];
$pdefnders = $playerinfo3['defence'];
$plevel = $playerinfo3['level'];
$pland = $playerinfo3['land'];
$playersr = $playerinfo3['successrate'];



$newsr = $playerinfo3['attack'] * 10 + $playerinfo3['land'] * 3 + $playerinfo3['level'] * 2 + $playerinfo3['defence'] * 10;

 $updateplayer="update players set successrate = '$newsr'";
	   mysql_query($updateplayer) or die ("could not update player");


	   ?>

successrate stand for a ranking system the rest you should be familler with,
now my question is how do i update every player,but for there own successrate, and not all get the same result defends on who's session is on...

Re: updating to many things.. help please =)

Posted: Mon Dec 13, 2010 3:35 pm
by hallsofvallhalla

Code: Select all

<?php
$playerinfo ="select * from players";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
 while($playerinfo3=mysql_fetch_array($playerinfo2))
      {


$playername = $playerinfo3['name'];



$newsr = $playerinfo3['attack'] * 10 + $playerinfo3['land'] * 3 + $playerinfo3['level'] * 2 + $playerinfo3['defence'] * 10;

$updateplayer="update players set successrate = '$newsr' where player ='$playername' ";
      mysql_query($updateplayer) or die ("could not update player");

}
      ?>
you may need to tweak it to get it to work like you want.

Re: updating to many things.. help please =)

Posted: Mon Dec 13, 2010 5:47 pm
by zvi5
"could not update player"
:?:

umm i mean in theory it is supposed to work,

what i am trying to do is make a"general number" witch later will be the rank system but how it works is it takes your "attack level times by 10 defence level times by 10,your "level" level *3 and your "land" amount times by 2,becouse people will have a lot of land,

what i am actully tring to do is make a ranking system by who has more ect....
if you have any idea or want me to post my sql db/code please tell me...
since what i did above is always giving errors when i add the "$playerinfo3['attack']"ect and only multiplaying the numbers...


thank-you again zvi5 =)

Re: updating to many things.. help please =)

Posted: Mon Dec 13, 2010 6:58 pm
by hallsofvallhalla
well does your player table have name? or is it player? I do not know this so thats what i mean by tweaking. Does it have successrate?

Code: Select all

$playerinfo3['defence']
is that right?

or should it be

Code: Select all

$playerinfo3['defense']

Re: updating to many things.. help please =)

Posted: Mon Dec 13, 2010 9:08 pm
by zvi5
I know its really big,sorry but i think that kind of explanes :O
if you have ANY clue what i should do please help!
you'll get a vertial cookie for free!!! <- jk.(if you hate sarcasem please dont hate here)
thank-you all very much and espesically you halls =)
gratz on the girl.

*EDIT:im really bad with graphicsa i might refer to that sub fourm later in the game development =)
**EDIT:Remember my problem is that it is updating all the players or dieing :O, !!by the way this will be a cron job!!(does it need ajax/java?)
Image

Re: updating to many things.. help please =)

Posted: Tue Dec 14, 2010 11:36 pm
by Baseball435
This is just a suggestion but make your $playerinfo3[''] things into variables. Won't make it so confusing to look at. Like..

Code: Select all

$defense = $playerinfo3['defense'] 
And also try and put ( ) in-between your math stuff like..

Code: Select all

 ($playerinfo3['attack'] * 10) + ($playerinfo3['land'] * 3)

Re: updating to many things.. help please =)

Posted: Wed Dec 15, 2010 10:21 am
by zvi5
not much of a clue what i did,was playing with it for like un hour :P
thanx for all the help,for some reason if i make it seperate it works.... =)

Code: Select all

<?php

$playerinfo ="select * from players";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
 while($playerinfo3=mysql_fetch_array($playerinfo2))
 {
$pattack = $playerinfo3['attack'];
$pdefence = $playerinfo3['defence'];
$plevel = $playerinfo3['level'];
$pland = $playerinfo3['land'];
$name = $playerinfo3['name'];
///$pid = $playerinfo3['id'];
$totalsr = ($pattack * 10) + ($pland * 3) + ($plevel * 2) + ($pdefence * 10);



 $updateplayer="update players set totalsr = '$totalsr' where name ='$name'";
 mysql_query($updateplayer) or die ("could not update player");
}

 ?>