I have this table in phpmyadmin
table
and I already have the connection and the value is stored here $row["Risco"]
and I have this table that are squares squares
.tabela-botoes-extincao{ width: 100%; height: 90px; padding-top: 30px; padding-bottom: 20px; font-weight: bold; } .espaco-botoes-extincao{ width: 14.28%; height: 90px; background-color: #cfcfcf; font-size: 19px; font-family: sans-serif; } .extincao-ativo{ background-color: #e8bc5d; }
<table class="tabela-botoes-extincao"> <tr> <th class="espaco-botoes-extincao"> Não Avaliada </th> <th class="espaco-botoes-extincao extincao-ativo"> Pouco Preocupante </th> <th class="espaco-botoes-extincao"> Vuneravél </th> <th class="espaco-botoes-extincao"> Em Perigo </th> <th class="espaco-botoes-extincao"> Criticamente em Perigo </th> <th class="espaco-botoes-extincao"> Extinta na Natureza </th> <th class="espaco-botoes-extincao"> Extinta </th> </tr> </table>
and then I want to put the class extinction-active
that changes the color of the square in the corresponding square that comes from the database
the goal is to change the color according to what is received from the database and I thought about using this way and maybe using a switch but I don’t know how to implement it …. I accept different proposals
Advertisement
Answer
already thought of a way, it gets big but it works
<table class="tabela-botoes-extincao"> <tr> <?php $nivel=$row["Risco"]; switch ($nivel){ case "Não Avaliada": echo "<th class='espaco-botoes-extincao extincao-ativo'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Pouco Preocupante": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Vuneravél": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Em Perigo": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Criticamente em Perigo": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Extinta na Natureza": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao'>Extinta</th>"; break; case "Extinta": echo "<th class='espaco-botoes-extincao'>Não Avaliada</th>"; echo "<th class='espaco-botoes-extincao'>Pouco Preocupante</th>"; echo "<th class='espaco-botoes-extincao'>Vuneravél</th>"; echo "<th class='espaco-botoes-extincao'>Em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Criticamente em Perigo</th>"; echo "<th class='espaco-botoes-extincao'>Extinta na Natureza</th>"; echo "<th class='espaco-botoes-extincao extincao-ativo'>Extinta</th>"; break; } ?> </tr> </table>