Basic Maths Equation
Posted: Tue Apr 25, 2006 10:05 pm
This is going to sound stupid, but I've never done any maths equations in PHP before so I thought I'd probably get a fairly fast answer here.
What I have is two values coming from a database which represent a home team's goals, and away team's goals, in a soccer game (eg 4 and 5). I want to display on the page who the winner was, so basically, I want to subtract the second value from the first one, and if the value is positive, set the result to "home". If it's even (i.e. the two values were the same), set the result to "draw", and if the value is negative, set the result to "away". Here's what I've got:
I know it's probably simple as hell but I'm not sure if there's a much easier way or whatever. Any help would be greatly appreciated.
What I have is two values coming from a database which represent a home team's goals, and away team's goals, in a soccer game (eg 4 and 5). I want to display on the page who the winner was, so basically, I want to subtract the second value from the first one, and if the value is positive, set the result to "home". If it's even (i.e. the two values were the same), set the result to "draw", and if the value is negative, set the result to "away". Here's what I've got:
Code: Select all
$difference = $current_page['home_team_goals'] - $current_page['away_team_goals'];
if ($difference >= 1) { $result= "home"; }
elseif ($difference <= -1) { $result= "draw"; }
else { $result= "away"; }