0

Good Morning,

I am looking for some code that will simply echo "0" when the result is negative. I dont want it to output a negative number.

Here is the line I am looking to add this to:

echo $row['GP1011_'.$wk.'']-$row['GP1011_'.$prev.''];

Any help is appreciated.
Thanks
Chris

Edited by ceeandcee: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nevvermind
1
$diff = $row['GP1011_'.$wk.''] - $row['GP1011_'.$prev.''];

// compact-nerdy style:
echo ($diff > 0) ? $diff : 0;

// or, for better reading:
if ($diff > 0) {
    echo $diff;  
} else {
    echo 0;
}

Edited by nevvermind: n/a

Votes + Comments
thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.