alex_01573 alex_01573 - 9 months ago 31
PHP Question

Coloring the rows depending on a particular column's value

I am trying to color each row separately depending on the value of fact for each one of them. Instead, all I manage to do is to turn the whole table grey. I guess that the last value if fact is 'N' and so the last if is in effect. How do I cope with this?
Below is my code.

while($row= mysqli_fetch_array($query))
echo '<tr style="background-color:green">';
echo '<tr style="background-color:red">';
echo '<tr style="background-color:grey">';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['nume_port'].'</td>';
echo '<td>'.$row['adr'].'</td>';
echo '<td>'.$row['fact'].'</td>';
echo '<td>'.$row['owner'].'</td>';
echo '<td>'.$row['nivel'].'</td>';
echo '<td>'.$row['chei'].'</td>';
echo '<td>'.$row['rezon'].'</td>';
echo '<td>'.$row['dist'].'</td>';
echo '<td>'.$row['ult_inc'].'</td>';

Edit: this question is not a duplicate, since I've not suspected that the equals are the problem. I thought there's a problem with the method I used.


You need to use == for comparison and not just = since that is an assignment operator.