Jump to content

[SOLVED] PHP Calculations (specifically involving zero)


Siggles

Recommended Posts

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

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.