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

Member Avatar for nevvermind
$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;
}
commented: thanks +1
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.