Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    CSS
    CSS is offline
    New Coder
    Join Date
    Jun 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Helping Average Out Values

    I need help. You can see what I've done @ http://egsl.enguards.net/lolurdumb/s...p?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 Code:
    <?php

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

      
    /**
       * Adress for delivery
       * 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($resultMYSQL_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_avghearts`='$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($resultMYSQL_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_avghearts`='$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());
      }

        
    mysql_close($link);
    ?>

  • #2
    CSS
    CSS is offline
    New Coder
    Join Date
    Jun 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I usually dig these kinds of issues out by adding echo statements of variables before and after the relevant calculations. That gives you helpful info as to how the calculation is going astray. I obviously can't do that with your script.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •