Ayaz
Ayaz

Reputation: 171

Changing font color of a row according to value from mysql table

I am using mysql queries to fetch data from db. All my data are showing fine in tables. Now I want to color the 'ASR' column if the value is less than 30 . The below code is not working. Need help.

<?php
while ($report=$records->fetch_assoc()) {                         
echo "<tr>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
echo "<td border='1'>".$report['Ingress']."</td>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
echo "<td border='1'>".$report['Attempts']."</td>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
if ($report['ASR'] < 30) 
{                               
echo "<td border='1' color='red'>".$report['ASR']."</td>";
}
else
{   echo "<td border='1'>".$report['ASR']."</td>";
}                           
?>

Upvotes: 0

Views: 523

Answers (1)

Rayon
Rayon

Reputation: 36609

color is a css property, use style attribute and place values as style = "property : value"

Also note that value of the property is not suppose to be in the quotes all the time.

<?php
while ($report=$records->fetch_assoc()) {                         
echo "<tr>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
echo "<td border='1'>".$report['Ingress']."</td>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
echo "<td border='1'>".$report['Attempts']."</td>";
?><td style="border:1px solid #DCD6D6; text-align: center;>"<?php
if ($report['ASR'] < 30) 
{                               
echo "<td border='1' style=\"color:red\">".$report['ASR']."</td>";
}
else
{   echo "<td border='1'>".$report['ASR']."</td>";
}                           
?>

PHP Fiddle

Upvotes: 2

Related Questions