Nathan
Nathan

Reputation: 1

Dynatable Row color with a class

I found a topic that discussed how to change an html table's row color based on a row's value. In my case, that solution didn't work. I would like to change the color of each row based on the value of the class associated with the table row. As an example: where the class of the is "red" in red, color the row red, but maintain a default color for others. What can I do to make this work?

    <table class="table table-striped" id="mytable">
      <thead>
        <tr>
          <th>Nom du cours</th>
          <th>Matière</th>
          <th>Date d'enregistrement</th>
          <th>Date d'apprentissage</th>
          <th>Nombre d'études</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody>
        <?php
          while($cour = $load->fetch()){
            if(condition){
                $data = "red";
            }else{
                $data = "none";
            }
            echo '
                <tr id = "cours_row" class='.$data.'>
                <td class="nom_cours">'.$cour['nom_cours'].'</td>
                <td class="nom_matiere">'.$cour['nom_matiere'].'</td>
                <td class="first_append">'.$cour['first_append'].'</td>
                <td class="next_append">'.$formater -> format(strtotime($cour['next_append'])).'</td>
                <td class="number_append">'.$cour['number_append'].'</td>
                <td class="actions">Actions</td>
            </tr>
            ';
           }
         ?>
      </tbody>
    </table>

Upvotes: 0

Views: 183

Answers (1)

ErTR
ErTR

Reputation: 905

Deciding what to assign in PHP:

$data = condition?"red":"natural";

CSS:

.red {
    background-color: red;
}
.natural {
    background-color: inherit;
}

Upvotes: 0

Related Questions