On my results page I have a while loop that is retrieving data from mysql and displaying it in a table. The table includes both home team and away team, half time score and full time score.
I’ve then got a bit of code that splits the home value and away value from full time score:
$value = $fulltime;
$apart = explode('-',$value);
I’ve then got an IF statement to firstly check if the home value is larger than the away value and then if the home id is the same as the winningid the user selected.
I’ve then done this for away win and if the game was a draw.
if($apart[0] > $apart[1]) {
if($row["home_id"]==$row["winningid"]) {
$hometeamwin = "Win";
}
} else if($apart[0] < $apart[1]) {
if($row["away_id"]==$row["winningid"]) {
$hometeamwin = "Win";
}
} else if($apart[0] == $apart[1]) {
if(!$row["winningid"]) {
$hometeamwin = "Win";
}
} else {
$hometeamwin = "lose";
}
echo $hometeamwin;
what am I doing wrong in the IF statement?
What is wrong is you won’t ever get to your fourth option and so therefore nobody will ever lose!
I do believe it should be this:
You need to check whether the [ACTUAL WINNING TEAM]’s ID is equal (or not) to the [CHOSEN TEAM]’s ID whilst checking who won not if the condition is true.
It’s not pretty but I think that’s what you’re going for.