如何在表格中回显数字时将数据库中的数字转换为颜色? (SQL PHP)

I made a echo table in PHP and when I test it, it gives me my table with data.

id    material    state    date
1     gold        100      2018-16-11
2     iron        75       2018-16-11
3     silver      25       2018-16-11

This is my table above. I can display this as a table, but I want it to be colored. When a state is higher than 80, it should be green, between 50 and 80 it should be yellow etc.

How to do it?

You can solve this in alot of ways. This should work

<td style="background-color:<?php if($state > 80){ echo 'green';} elseif($state > 50 && $state < 80){ echo 'yellow'} ?>;"> 
    <?php echo $state; ?> 
</td>