0

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.

<?php
while($row= mysqli_fetch_array($query)) 
{
if($row['fact']='E')
    echo '<tr style="background-color:green">';
if($row['fact']='R')
    echo '<tr style="background-color:red">';
if($row['fact']='N')
    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>';
echo'</tr>';
}?>

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.

i01573
  • 75
  • 2
  • 11
  • 1
    Wrong equals. One sets, two and three compare. Three compares more strictly, also checking variable type. So currently all conditions are met and since `gray` is your last case you get `gray`. You might want to use a `switch` there, then only one case could be met. – chris85 Jul 02 '16 at 13:45
  • The switch is a good idea, thank you. – i01573 Jul 02 '16 at 14:05

1 Answers1

2

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

References:

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141