Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

php - put a class in the table according to the database

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>
question from:https://stackoverflow.com/questions/65865188/put-a-class-in-the-table-according-to-the-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...