I have this code in my table calling in a number

    <td>Total: <?php echo $total_credit;?></td>

I would like to change the background colour or the text colour depending on whether this value is equal to or higher than 2, is there an easy way I could do this with an If statement?

Thanks for any help in advance!

  • 1
    You can ask this question at stackoverflow.com this site is particularly for WordPress development related questions. Thanks! – jas Dec 9 '15 at 10:20

Here is the updated code with condition

    <td <?php if($total_credit >= 2): ?> style="background-color:#000000;" <?php endif; ?>>
        Total: <?php echo $total_credit;?>

Change #000000 to appropriate color code. Then the background color will be changed. Use same logic for changing the text color.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.