This is a partial of the code I have on my script. I have tried to make the backgrounds change color depending on the values and can't get it to read the arrays correct. Placing the conditions outside the while or inside the while returns same results when printed.

If the value is 100, the color should be RED
If the value is above 49, the color will be yellow
If the value is 0 to 49, the color will be green

Will appreciate if someone would find how the BILLED_TO_DATE_PERCENTAGE would change depending on number range when SQL read pulls data.

$counter = 1;

while($row = mysqli_fetch_array($result))

    echo "<tr>"; 
    echo "<td bgcolor=#001F25>" . "<b>" . "<font color=WHITE>" . $counter . "</font>" . "</b>" . "</td>";
    echo "<td bgcolor=#00353F>" . "<b>" . "<font color=WHITE>" . $row['NUMBER'] . "</font>" . "</td>";
    echo "<td bgcolor=#00353F>" . "<b>" . "<font color=WHITE>" . $row['PROJECT'] . "</font>" . "</td>"; 
    echo "<td style=\"$tdStyle\">" . "<b>" . "<i>" . $row['BILLED_TO_DATE_PERCENTAGE'] . "</i>" . "</b>" . "</td>";
    echo "</tr>"; 
    $counter++; //increment counter by 1 on every pass
echo "</table>";

In your conditional statement I spot to things wrong you are using the wrong reference to the variable it should be $row['BILLED_TO_DATE_PERCENTAGE']and also when doing a comparison you use == to test if 2 values match, using a single = tells PHP to set the variable to the following value, which will return true so will always use the first condition.

You can also make it simpler and use "else if"

if($row['BILLED_TO_DATE_PERCENTAGE'] == 100){
    $tdStyle = 'red';
}elseif($row['BILLED_TO_DATE_PERCENTAGE'] > 79){
    $tdStyle = 'green';
}elseif($row['BILLED_TO_DATE_PERCENTAGE'] > 59){
    $tdStyle = 'blue';
    $tdStyle = 'white';
echo "<td style='background-color:{$tdStyle};'>{$row['BILLED_TO_DATE_PERCENTAGE']}</td>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.