...

View Full Version : Helping Average Out Values

CSS
08-06-2007, 05:55 AM
I need help. You can see what I've done @ http://egsl.enguards.net/lolurdumb/singles.php?mode=matches or ?mode=scores
Anyway, this takes fights from an online game and records them to this site, which then displays a top points/scores list using the formula (avg. hearts left)*((win%(10000))
The thing is, I'm noticing the averaging of the hearts takes the players CURRENT average hearts, adds it to the # of hearts they are left with the next match, and divides that by 2, rather than dividing it by "match_all"
For example, if a player has played 4 matches and his current HP is 4. The next match, he wins with 2 HP left. His average hearts now displays as 3, rather than some decimal below 1.
Can anyone please fix this for me?
<?php

include("anotherwhatever.php");
\$playerOne = \$_GET['playerOne'];
\$playerTwo = \$_GET['playerTwo'];
\$heartsOne = \$_GET['heartsOne'];
\$heartsTwo = \$_GET['heartsTwo'];

/**
* http://egsl.enguards.net/lolurdumb/whatever.php?playerOne=Acc1&playerTwo=Acc2&heartsOne=1&heartsTwo=0
*/

\$query = "INSERT INTO `singles_match` (playerOne,playerTwo,heartsOne,heartsTwo)
VALUES ('\$playerOne','\$playerTwo','\$heartsOne','\$heartsTwo')";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());

if (\$heartsOne > \$heartsTwo) {
\$stats[0][0] = 1; // won
\$stats[0][1] = 0; // lost
\$stats[1][0] = 0;
\$stats[1][1] = 1;
}else{
\$stats[0][0] = 0; // won
\$stats[0][1] = 1; // lost
\$stats[1][0] = 1;
\$stats[1][1] = 0;
}

// Stats Player One
mysql_query("SELECT account FROM `singles_player` WHERE `account` = '\$playerOne'");
if (mysql_affected_rows() > 0) {
\$query = "SELECT match_all,match_won,match_lost,match_avghearts FROM `singles_player` WHERE `account` = '\$playerOne' LIMIT 1";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());

while (\$line = mysql_fetch_array(\$result, MYSQL_ASSOC)) {
\$match_allOne = \$line['match_all'] + 1;
\$match_wonOne = \$line['match_won'] + \$stats[0][0];
\$match_lostOne = \$line['match_lost'] + \$stats[0][1];
\$match_avgheartsOne = (\$line['match_avghearts'] + \$heartsOne) / 2;
}
if (\$match_wonOne == 0)
\$match_pointsOne = round(\$match_avgheartsOne * 10000,2);
else
\$match_pointsOne = round(\$match_avgheartsOne * ((\$match_wonOne/\$match_allOne)*10000),2);

\$query = "UPDATE `singles_player` SET `match_all`='\$match_allOne',`match_won`='\$match_wonOne',`match_lost`='\$match_lostOne',`match_avghear ts`='\$match_avgheartsOne',`match_points`='\$match_pointsOne' WHERE `account` = '\$playerOne' LIMIT 1";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());
}else{
\$match_wonOne = \$stats[0][0];
\$match_lostOne = \$stats[0][1];
if (\$match_wonOne == 0)
\$match_pointsOne = round(\$heartsOne * 10000,2);
else
\$match_pointsOne = round(\$heartsOne * (\$match_wonOne*10000),2);

\$query = "INSERT INTO `singles_player` (account,match_all,match_won,match_lost,match_avghearts,match_points)
VALUES ('\$playerOne',1,'\$match_wonOne','\$match_lostOne','\$heartsOne','\$match_pointsOne')";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());
}

// Stats Player Two
mysql_query("SELECT account FROM `singles_player` WHERE `account` = '\$playerTwo'");
if (mysql_affected_rows() > 0) {
\$query = "SELECT match_all,match_won,match_lost,match_avghearts FROM `singles_player` WHERE `account` = '\$playerTwo' LIMIT 1";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());

while (\$line = mysql_fetch_array(\$result, MYSQL_ASSOC)) {
\$match_allTwo = \$line['match_all'] + 1;
\$match_wonTwo = \$line['match_won'] + \$stats[1][0];
\$match_lostTwo = \$line['match_lost'] + \$stats[1][1];
\$match_avgheartsTwo = (\$line['match_avghearts'] + \$heartsTwo) / 2;
}
if (\$match_wonTwo == 0)
\$match_pointsTwo = round(\$match_avgheartsTwo * 10000,2);
else
\$match_pointsTwo = round(\$match_avgheartsTwo * ((\$match_wonTwo/\$match_allTwo)*10000),2);

\$query = "UPDATE `singles_player` SET `match_all`='\$match_allTwo',`match_won`='\$match_wonTwo',`match_lost`='\$match_lostTwo',`match_avghear ts`='\$match_avgheartsTwo',`match_points`='\$match_pointsTwo' WHERE `account` = '\$playerTwo' LIMIT 1";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());
}else{
\$match_wonTwo = \$stats[1][0];
\$match_lostTwo = \$stats[1][1];
if (\$match_wonTwo == 0)
\$match_pointsTwo = round(\$heartsTwo * 10000,2);
else
\$match_pointsTwo = round(\$heartsTwo * (\$match_wonTwo*100),2);

\$query = "INSERT INTO `singles_player` (account,match_all,match_won,match_lost,match_avghearts,match_points)
VALUES ('\$playerTwo',1,'\$match_wonTwo','\$match_lostTwo','\$heartsTwo','\$match_pointsTwo')";
\$result = mysql_query(\$query) or die("Request failed: " . mysql_error());
}