Use an if/elseif/else construct or a switch construct to set a CSS class name in a variable based on the specified conditions, then use that value for the HTML class attribute of the table row or whatever is holding the output text. Then style those classes as desired in your CSS stylesheet to have the desired background/foreground colors.