Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com > PHP Helping Average Out Values

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 08-06-2007, 06:55 AM PM User | #1 CSS 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: ```  \$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_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(\$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_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); ?> ```
 08-06-2007, 05:04 PM PM User | #2 CSS New Coder   Join Date: Jun 2006 Posts: 40 Thanks: 0 Thanked 0 Times in 0 Posts Anyone?
 08-06-2007, 07:12 PM PM User | #3 Fumigator UE Antagonizer     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. __________________ I heart Hostmonster

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 06:41 AM.