最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Change colour of table td based on value

programmeradmin3浏览0评论

I have this code in my table calling in a number

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

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!

I have this code in my table calling in a number

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

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!

Share Improve this question asked Dec 9, 2015 at 10:15 Lucy BrownLucy Brown 1491 gold badge3 silver badges11 bronze badges 1
  • 1 You can ask this question at stackoverflow this site is particularly for WordPress development related questions. Thanks! – jas Commented Dec 9, 2015 at 10:20
Add a comment  | 

1 Answer 1

Reset to default 0

Here is the updated code with condition

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

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

发布评论

评论列表(0)

  1. 暂无评论