2017-02-16 8 views
-2

Ich möchte die Farbe des Status ändern, die (Pending, Approved und Cancelled) dynamisch sind.Ändern Sie die Textfarbe abhängig vom Status

bisher bin ich hier mein Code aber die Farbe hat sich nicht geändert. Irgendein Vorschlag? danke im voraus

if ($status == 'Approved') 
          echo 'style="color: green;"'; 
         else if ($status == 'Cancelled') 
          echo 'style="color: red;"'; 
         else if ($status == 'Pending') 
          echo 'style="color: blue;"'; 

         echo '>'.$row['status'].'</th>'; 
+0

if ($ status == 'Approved') echo 'style = "Farbe: grün;"'; sonst if ($ status == 'Canceled') echo 'style = "color: red;"'; else if ($ status == 'Pending') echo 'style = "Farbe: blau;"'; echo '>'. $ Row ['status']. ' '; –

+0

Das ist mein Code bisher –

+0

in Ordnung. Entschuldigung für das –

Antwort

0

Könnten Sie das versuchen? Und vielleicht könnte es ein Großbuchstabe-Problem in "==" Operator geben, zum Beispiel, wenn Sie $ status = 'approved' definiert haben; es ist nicht mit grün zeigen. Es hat $ Status sein = ‚Genehmigt‘

<?php 
          if ($status == 'Approved') 
           $whatscolor = 'color: green'; 
          else if ($status == 'Cancelled') 
           $whatscolor = 'color: red'; 
          else if ($status == 'Pending') 
           $whatscolor = 'color: blue'; 
    ?> 

    <div style="<?php echo $whatscolor; ?>"><?php echo $row['status']; ?></div></th> 

Aber wenn Sie alle Web-Seite der Textfarbe ändern möchten, können Sie dies tun.

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Title of the document</title> 
<?php 
    //$status = "Pending"; it has to be defined before here. 
    if ($status == 'Approved') 
     $whatscolor = 'color: green'; 
    else if ($status == 'Cancelled') 
     $whatscolor = 'color: red'; 
    else if ($status == 'Pending') 
     $whatscolor = 'color: blue'; 
?> 
<style> 
body { 
    <?php echo $whatscolor; ?> 
    } 
</style> 
</head> 

<body> 
Content of the document...... 
</body> 

</html> 
+0

okay danke. Ich werde deinen Vorschlag versuchen. –

+0

Ich habe dir gesagt, dass du nur die Farbe von $ row ['status'] ändern willst. Wenn Sie dies tun möchten, wird diese Lösung Ihnen helfen. Aber du suchst etwas anderes, ich werde versuchen, trotzdem zu helfen. – marlonjd

+0

Ich möchte die Textfarbe abhängig vom Status ändern. –

0

Ich werde Ihnen Alternative geben,

<?php $row['status'] = "Approved"; ?> 
<div style="width: 100px;height:100px;display: block;border: 1px solid;<?php if ($status == 'Approved') { echo 'color: green;"'; } else if ($status == 'Cancelled') { echo 'color: red'; } else if ($status == 'Pending') { echo 'color: blue;'; } echo '">' . $row['status'] . '</div>'; 

überprüfen diese, seine Arbeitscode.

Verwandte Themen