I am trying to build a Standings page for a hockey pool site that shows Wins, Losses, Ties, etc.

I am struggling with the Tie section. If two teams have the same number of points (PF=PA) the team gets one point. I can get this part to work. However, at the very beginning of the game when it is 0-0, it still shows it as a TIE and awards 1 point for this. I want to put a condition that if both PF=0 and PA=0 that the point awarded should not be 1 but 0.

Here is what I have so far:

if ($row['PF_wk2'] == $row['PA_wk2']) {
$Tie="1";
} else {
if ($row['PF_wk2'] = "0" and $row['PA_wk2'] = "0") 
$Tie="0";
}
if ($row['PF_wk2'] != $row['PA_wk2']) {
$Tie="0";

}
echo $Tie;

Any help would be appreciated!

On line 4 the = should be ==

Your problem is not just from the single "=" vs the "==" but logically your if else wont work. Your first if statement "if ($row == $row)" will make $tie be equal 1 when the score is 0-0 since php wont even execute the else part of your code.

The way php will read and run your code is first it will check PF-wk2 with PA_wk2 if it equals (i.e. both are 0) then it will assigned 1 to $tie and skip the rest of the if - else statement.

A simple fix is just to leave out the else clause and have three separate if statement with no else. That way php will go through sequentially and change $tie to 0 after reading and runnning the first if statement.

Hi,

[EDIT: sorry... didn't see this marked as solved!]

if ($row['PF_wk2'] == $row['PA_wk2']) {
     // since PF == PA, just check one of them for being zero
     if ($row['PF_wk2'] == "0") {
          // tied at zero, award zero points
          $Tie="0";
     } else {
          // tied not at zero, award 1 point
          $Tie="1";
     }
} else {
     // not a tie, award no points
     // don't really need to do a != check here since it is implied by the first condition (==)
     $Tie="0";
}

echo $Tie;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.