Change Table Row Color based on a Database Value

Asked

Viewed 244 times

1

Good afternoon

I’m building a system, I register people in the database and I need that when I select a radio box on the page visita_registro.php which makes me include a record in the bank, record in the table color the id the selected color and the data that appear in the page table index.php the color I selected in the radio box on the previous page.

The colors are green, yellow, red and white. I read an article that is similar to what I want to do but the script did not work in my project.

If anyone can help me, the explanation is a little complex, but I hope you understand.

Part of the file visit_registro.php

<div class="panel panel-default">
        <div class="panel-heading">
            <p><span class="glyphicon glyphicon-comment"></span> Registro de Visitas</p>
        </div>
            <div class="panel-body">
                <form method="POST" action="visita_processa.php">
                    <!--Criando uma tag input com campo tipo hidden para enviar o id da linha que está em edição de forma oculta para o nosso arquivos de update -->
                    <input type="hidden" name="id" value="<?php echo $id; ?>">
                        <div class="form-group" class="styled-select">
                            <label for="pa">Situação:</label><br/>
                                <select name="situacao" class="form-control" >
                                    <option value="">Escolha o usuário</option>
                                    <?php
                                                $sql_at = "SELECT 
                                                            *
                                                             FROM 
                                                             rede_catarina.visitas_situacao
                                                            ORDER BY
                                                             id";

//Verifica se a consulta retornou mais de uma linha, se sim, mostra o conteúdo do banco,
                                                    $result_sql_at = mysqli_query($conn, $sql_at);
                                                        while($row_sql_at = mysqli_fetch_assoc($result_sql_at) ) {
                                                        echo '<option value="'.$row_sql_at['id'].'">'.utf8_encode($row_sql_at['situacao'].'</option>');

                                                        }
                                            ?>
                                </select>
                        </div>
                            <div class="form-group">
                                <label for="mensagem">Obs. Visita:</label><br/>
                                <textarea name="mensagem" class="form-control" rows="5" ></textarea><br/><br/>
                            </div>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="cor" name="cor" value="verde"> Visita Realizada<br>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="cor" name="cor" value="vermelho"> Visita com Alterações<br>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="cor" name="cor" value="amarelo"> Apreciado pelo Ministerio Público<br>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" id="cor" name="cor" value="branco"> Continuar Visitas<br><br><br> 
                                <input type="submit" value="Registrar" class="btn btn-primary" />
                </form>
        </div>
    </div>
  • You can put in the value radio box the name of the color according to the chosen option, and give a post on it or use Ajax to pick that value..

  • 2
  • Leandro, I thought the following, I hope I have coherence my thought: I need to insert the record there is that the line of the Index turns green after I selected the radio box, then the MP will see when I access that is green so they read the record and change to yellow, Then when I access I will know that they visualized and left a record with the opinion, then I go there and I pass to white after reading their opinion q the white means continues the visit if it will terminate inactive in the register

  • In index.php I have echo pulling the data from BD, I put the radio box with the name of each color that saves in the color table and the color id is in the table register, want q when pull the data table register to appear in the table of the page index.php do the reading of the column color and paint the line, but I do not know do not know if it has to do this at home javascript. If anyone can give a support in this situation. I am very grateful

  • If that line you want to color is a Div, using Javascript you locate the div var div = document.getElementById('minha_div'); and puts the color on it using the value that came from the bank’s select using the PHP div.style.background = <?PHP echo $cor; ?>;. I recommend it in a function onLoad.

  • Thank you very much Leandro I will try this alternative. It seems very simple I hope that solves my problem.

  • Leandro, in my page index.php has no debt I will post part of the code:

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.