how can i set the table tr background color according to same value in one row ?
<?php
$result = mysql_query("SELECT * FROM `status` where username ='".$UserName."' ",$conn);
while($row=mysql_fetch_array($result))
{
echo '
<tr style="'.$bgcolor.'">
<td>
'.$row["Uv"].'
</td>
<td>
'.$row["Su"].'
</td>
<td> '.$row["Status"].' </td>
</tr> ';
}
?>
How the rows should look like i wan't change color according to same uv like hmsid20161812(blue color), hmsid20161815(brown color), hmsid20161810 (yellow color) means we give color code or name in array but print according to uv.
You need to add background-color:
attribute of css before colour.
Change
<tr style="'.$bgcolor.'">
with
<tr style="background-color: '.$bgcolor.'">
you could try something like this and you should also change all your mysql_
functions to at least mysqli_
functions. Better try PDO. Have a look at this awasome blog here
<?php
$bgcolor = "blue"; //you have to define it somewhere like here
$bgcolor2 = "red"; //you have to define it somewhere like here
$bgcolor3 = "yellow"; //you have to define it somewhere like here
$result = mysqli_query("SELECT * FROM `status` where username ='".$UserName."' ",$conn);
while($row = mysqli_fetch_array($result))
{
if ($row['Uv'] == "hmsid20161812") {
echo "<tr style='background-color: $bgcolor'>
<td>
".$row['Uv']."
</td>
<td>
".$row["Su"]."
</td>
<td> ".$row["Status"]." </td>
</tr> ";
} elseif ($row['Uv'] == "hmsid20161815") {
echo "<tr style='background-color: $bgcolor2'>
<td>
".$row['Uv']."
</td>
<td>
".$row["Su"]."
</td>
<td> ".$row["Status"]." </td>
</tr> ";
}
elseif ($row['Uv'] == "hmsid20161810") {
echo "<tr style='background-color: $bgcolor3'>
<td>
".$row['Uv']."
</td>
<td>
".$row["Su"]."
</td>
<td> ".$row["Status"]." </td>
</tr> ";
}
}
?>