Problem with writing an if-else statement for a sports website. The key is to display $game as W, L, or Tie depending on the scores which are parsed from a MySQL table from a variable called $row["result"]. The type of the column in table is VARCHAR and format the data saved in is $row["result"] = "A:B" where A is the home team’s score and B is the opponents score. I am running into a problem where I write the if statement I can only echo Wins (W) and Ties (Tie) correctly!
For example the code:
<?php
$wl = $row["result"];
if ($wl[1] > $wl[3]) {
$game = "W";
}
if ($wl[1] < $wl[3]) {
$game = "L";
}
if ($wl[1] == $wl[3]) {
$game = "Tie";
}
?>
$game will output correctly when $wl= A>B and A==B but not A<B. I have a feeling this has something to do with PHP interpreting the data from $wl as not numbers, but some other format…
I’d also recommend using explode(), but for what you’re using I think you should be referencing $wl[0] and $wl[2], since the array $wl starts at zero index.