0

I'm creating a football betting game in PHP/MSQL and right now im trying to calculate the scoring system with if-statements.

the bets are saved per team like this:

Team 1: Bayern Munich  
Team 2: Borussia Dortmund

Bet_Team1: 4  
Bet_Team2: 1

The actual results:
Bayern Munich 5:2 Borussia Dortmund

saved like this:

Result_Team1: 5
Result_Team2: 2

I tried this with if statements:

// Completely right draw:    
if($Bet_Team1 === $Result_Team1 && $Bet_Team2 == $Result_Team2){
    $points = $points+6; }

It works well, but i don't know how to calculate the points, if the user bets the right winner team like in the example above with Bayern Munich and Borussia Dortmund.

blzzrd
  • 3
  • 2
  • They bet 4-1 but result was 5-2 So they are not `===` or even `==` – RiggsFolly May 16 '16 at 10:18
  • hey, the if-statement is just an example for calculating a draw game. – blzzrd May 16 '16 at 10:24
  • Can you please explain what isn't working? – fislerdata May 16 '16 at 10:25
  • Well all you need to do is build another if, it will be more complex, but have a go and then we have a better idea what you actually want to do – RiggsFolly May 16 '16 at 10:25
  • @fislerdata It not that its not working, he just cannot see how to write the next IF statement. _So its a code it for me question really_ – RiggsFolly May 16 '16 at 10:26
  • i don't now how to calculate the points, if the user bets the right winner team . Bet: 4:1 Result 5:2. I tried `code $TippT1 > $TippT4 && $ET1 > $ET4` but this does not work – blzzrd May 16 '16 at 10:30

1 Answers1

1

How about this to get you started

// Completely right draw:    
if($Bet_Team1 === $Result_Team1 && $Bet_Team2 == $Result_Team2){
    $points = $points+6; 
}
// they guessed the winning team but wrong score
else if ( ($Result_Team1 > $Result_Team2 && $Bet_Team1 > $Bet_Team2) ||
          ($Result_Team2 > $Result_Team1 && $Bet_Team2 > $Bet_Team1)
        ) 
{
    $points += ?  // how many points do you allocate to this situation
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Works great! Thank you! – blzzrd May 16 '16 at 10:38
  • 1
    A nice implementation of this in php7 would be to use the [spaceship operator](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php/31298778#31298778). Something like: `if(($bet_team1 <=> $bet_team2) == ($result_team1 <=> $result_team2)){ // add points }` This will also account for incorrect scores on draws. – ImClarky May 16 '16 at 10:38