I am trying to change the background color of the text with a given condition. When the condition is met, the color will be changed. Here is the code I used But I got nothing in return. I tried to echo the color to see the color variable is working or not. Still, I got nothing. What is the problem here? Thanks in advance.
<?php while($row = mysqli_fetch_assoc($result1)) { $dersevrakno =$row['Enstitu_KararNo']; $bolum = $row['EABD_EvrakNo']; $status = $bolum ? $bolum : NULL; //it says $bolum is empty = $status ( not sure its correct) if(empty($dersevrakno) && $row['OgrenciNo'] == $user_studentid){ while ($status){ $color ="blue"; echo $color; // to see $color is working or not } ?> <tr> <td><?php echo $row["formgonderme"]; ?></td> <td><?php echo $row["O_AdiSoyadi"]; ?></td> <td><?php echo $row["OgrenciNo"]; ?></td> <td><?php echo $row["Derece"]; ?></td> <td width="4%" style="background-color:<?php echo $color;?>"> Bölüm Sekreterliği</td></tr> <?php } } ?>
Advertisement
Answer
The issue that you are having is that you have an extra double “ quote in your style.
Updated code:
<td width="4%" style="background-color:<?php echo $color;?>">
I can also recommend that you use a class so you can update different properties on the element with only it and you can used it on different tables and have the same consistent format.
Update to address if/while:
if(!empty($dersevrakno) && $row['OgrenciNo'] == $user_studentid && !empty($status)){ $color ="blue"; echo $color; // to see $color is working or not }else{ // set a default color $color="white"; }