2017-05-23 4 views
-2

ich habe einige probleme mit meinem code.ändern bootstrap label hängen von den wörtern von mysql reihe

Ich möchte die Farbe auf meinen Etiketten ändern, wenn es von einem Status zu einem anderen abhängig von der Welt von mysql db geht.

Zunächst einmal habe ich den Code:

<table class="table responsive"> 
        <div id="employee_table"> 
          <table class="table"> 
           <tr> 
            <th width="10%">ARK ID</th> 
            <th width="20%">User</th> 
            <th width="45%">Header</th> 
            <th width="10%">Status</th> 
            <th width="20%">Priority</th> 

           </tr> 
           <?php 
           while($row = mysqli_fetch_array($result)) 
           { 
           ?> 
           <tr> 
            <td><?php echo $row["ark_id"]; ?></td> 
            <td><?php echo $row["name"]; ?></td> 
            <td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td> 
            <td><?php echo $row["prioritet"]; ?></td> 
            <td><?php echo $row["status"]; ?></td> 

            </tr> 
           <?php 
           } 
           ?> 
          </table> 

Zweitens, werde ich Status und Priorität Etikett Farbe wie diese zu ändern, wenn Priorität LOW dann Green Label ist Wenn Priorität MEDIUM ist dann Blau wenn Priorität HIGH dann RED

... die gleiche Funktion über den Status Pending .... Und so weiter ..

ich hoffe, dass mir jemand helfen könnte :)

Vielen Dank!

Antwort

0

Hoffnung Code unten helfen Ihnen

<table class="table responsive"> 
    <div id="employee_table"> 
     <table class="table"> 
      <tr> 
       <th width="10%">ARK ID</th> 
       <th width="20%">User</th> 
       <th width="45%">Header</th> 
       <th width="10%">Status</th> 
       <th width="20%">Priority</th> 
      </tr> 
      <?php 
      while($row = mysqli_fetch_array($result)) 
      { 
       if($row["prioritet"] == "LOW") { 
        $priority_color = '#009933'; // low priority color 
       } 
       else if($row["prioritet"] == "MEDIUM") { 
        $priority_color = '#0099ff'; // Medium priority color 
       } 
       else if($row["prioritet"] == "HIGH"){ 
        $priority_color = '#ff0000'; // High priority color 
       }else{ 
        $priority_color = '#ffffff'; // default color 
       } 
      ?> 
      <tr> 
       <td><?php echo $row["ark_id"]; ?></td> 
       <td><?php echo $row["name"]; ?></td> 
       <td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td> 
       <td><?php echo $row["prioritet"]; ?></td> 
       <td bgcolor="<?php echo $priority_color; ?>"><?php echo $row["status"]; ?></td> 
      </tr> 
      <?php 
      } 
      ?> 
</table> 
+0

Ich war ein paar Zeilen fehlt, sorry! :) Es ist alles gut jetzt. Danke für Ihre Hilfe! –

+0

Entschuldigung dafür, dass du dir Zeit genommen hast, aber mir fehlte ein Code - Der andere Teil meines Codes, der "Status", war nicht in diesem Code, wie mache ich einen IF-Satz mehr? –

+0

Bitte erläutern Sie mehr über Ihre Frage, damit wir Ihnen helfen können. –

2

könnten Sie überprüfen die Priorität auf den Beginn der while-Schleife:

<table class="table responsive"> 
    <div id="employee_table"> 
     <table class="table"> 
      <tr> 
       <th width="10%">ARK ID</th> 
       <th width="20%">User</th> 
       <th width="45%">Header</th> 
       <th width="10%">Status</th> 
       <th width="20%">Priority</th> 
      </tr> 
      <?php 
      while($row = mysqli_fetch_array($result)) 
      { 
       if($row["prioritet"] == "LOW") { 
        $color = '#000000'; // choose color 
       } 
       else if($row["prioritet"] == "MEDIUM") { 
        $color = '#888888'; // choose color 
       } 
       else { 
        $color = '#ffffff'; // choose color 
       } 
      ?> 
      <tr> 
       <td><?php echo $row["ark_id"]; ?></td> 
       <td><?php echo $row["name"]; ?></td> 
       <td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td> 
       <td style="color:<?php echo $color?>"><?php echo $row["prioritet"]; ?></td> 
       <td style="color:<?php echo $color?>"><?php echo $row["status"]; ?></td> 
      </tr> 
      <?php 
      } 
      ?> 
</table> 
Verwandte Themen