Forum Moderators: coopster
this can be a positive value or a negative value.
I need to output the variable in html depending on its value. If the value is negative, display it in red (e.g. if $val=-25., display 2.5 in red color). If it is positive, display it in green (e.g. if $val=25., display 2.5 in green color)
Would appreciate any help
Thanks!
Another way to do it would be to use CSS and a class. Here, I'll demonstrate the ternary conditional operator [php.net]:
<style type="text/css">
p.red {
color: red;
}
p.green {
color: green;
}
</style>
<p class="<?php print $val < 0? 'red' : 'green'; ?>"><?php print $val; ?></p>
if ($val < 0) {
$val = [url=http://uk3.php.net/manual/en/function.substr.php]substr[/url]($val, 1);
}
<edit>
You can use the ternary operator for this as well, but an if block may well be easier to read ;)
[edited by: PHP_Chimp at 10:39 pm (utc) on Feb. 1, 2008]
[uk3.php.net...]