php colour table data based on conditions
Posted: Fri Mar 26, 2010 8:59 am
Hello all,
I am working on php code to colour the data in html table based on given conditions.
The data in second column should be in red colour if the data in fifth column is greater than 0.5 and turn green if it is less than 0.5. Similarly third column should apply the colour condition based on the data in sixth column. The code which I have given below applies the condition to all the data. But I need to colour the data based on the corresponding coulmn values.
I tried a lot, but couldn't figure out how to write a query statement to look for certain coulmn and based on that to colour the values in other column. Could anyone lead me to right direction? Any ideas would be much helpful. Thanks in advance.
I am working on php code to colour the data in html table based on given conditions.
The data in second column should be in red colour if the data in fifth column is greater than 0.5 and turn green if it is less than 0.5. Similarly third column should apply the colour condition based on the data in sixth column. The code which I have given below applies the condition to all the data. But I need to colour the data based on the corresponding coulmn values.
I tried a lot, but couldn't figure out how to write a query statement to look for certain coulmn and based on that to colour the values in other column. Could anyone lead me to right direction? Any ideas would be much helpful. Thanks in advance.
Code: Select all
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr border='2' bordercolor= '#000033' bgcolor='#FFFFB5'>";
foreach ($rows as $data){
if($data >"0.5"){
$bgcolor="red";
}
else{
$bgcolor="green";
}
echo "<td align='center' bgcolor='$bgcolor'>". $data . "</td>";
}
}