How to make a background-color in <td> in php?

Hi every body;
I want to make a background-color in php. I have some code like this:

<td><?php echo $oq; 
if ($oq<0) {
 echo  ' style="background-color:red;"';

But, it cannot make a background-color. How to do that?
Thanks in advance

A. You should use a css class to do this, so that if at any time you want to change anything about the styling, you can do so in one place by changing the css definition.
B. Any css/styling goes inside the opening <td ...> tag, which a quick web search would have shown you how to do.

Btw - the </> preformatted text forum button is only for a word or phrase and didn’t work around your code, since it contains more than a single line. Use either bbocde code tags [code][/code] or triple-back ticks around a block of code.

1 Like

Something like this

   	if ($oq < 0) {
       echo "<td class='red'>" . $oq . "</td>";
     } else {
       echo "<td class='blue'>" . $oq. "</td>";
Sponsor our Newsletter | Privacy Policy | Terms of Service