Siggles Posted August 26, 2008 Share Posted August 26, 2008 Hi, I run a prediction league. At the heart of the prediction league is a script that runs some calculations on the result of the game and the score predicted by the user. For the last 2 games it has worked well. At the weekend a game drew 0-0 and now it has given everyone the score 0. Here is the code for the calculation script... I hope the variables used speak for themselves.. What can be going wrong here? Thanks. <? function calc_score($score_home, $prediction_home, $score_away, $prediction_away) { global $sum; global $correctresult; global $totaldiff; if ($score_home==$prediction_home && $score_away==$prediction_away) {//correctly predicted score - Rule 1 $sum+=25; } elseif ($score_home==$score_away && $prediction_home==$prediction_away) { //both draw so 10 points - Rule 2 $sum+=10; $correctresult=10; //used for correct result total in league table } elseif ($score_home>$score_away && $prediction_home > $prediction_away) { //both win so 10 points - Rule 2 $sum+=10; $correctresult=10; } elseif ($score_home<$score_away && $prediction_home < $prediction_away) { //both lose so 10 points - Rule 2 $sum+=10; $correctresult=10; } else { $correctresult=0; } $totalresult = $score_home + $score_away; //works out total goals of game $totalpredict = $prediction_home + $prediction_away; //works out total goals of prediction //works out difference between total goals for result and for prediction if ($totalresult > $totalpredict) { $totaldiff = $totalresult - $totalpredict; $sum-=$totaldiff; } elseif ($totalpredict > $totalresult) { $totaldiff = $totalpredict - $totalresult; $sum-=$totaldiff; } $totaldiff = -$totaldiff; //totaldiff is added to dbase and used in league table for goal accuracy } ?> Link to comment https://forums.phpfreaks.com/topic/121375-solved-php-calculations-specifically-involving-zero/ Share on other sites More sharing options...
kenrbnsn Posted August 26, 2008 Share Posted August 26, 2008 How is this function used? Ken Link to comment https://forums.phpfreaks.com/topic/121375-solved-php-calculations-specifically-involving-zero/#findComment-625901 Share on other sites More sharing options...
Siggles Posted August 26, 2008 Author Share Posted August 26, 2008 This is fixed now. Thanks for looking. Turns out the function is fine but I was using php empty function somewhere else and 0 counted as empty. Link to comment https://forums.phpfreaks.com/topic/121375-solved-php-calculations-specifically-involving-zero/#findComment-626018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.