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

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.