Show customer data by clicking name

Asked

Viewed 54 times

0

I need to have you show me a list of the clients' names, and when you click on a button or the client’s name, the customer’s data will appear, but I have no idea how to proceed. I tried to show the data in a pop-up, but also without success.

There are two fields the name the action, the difficulty itself is in the action field.

Follow code done so far:

  <table id="data-table" class="table">           
     <thead>
         <tr>
           <th>Nome</th>
           <th>Ação</th>
        </tr>
    </thead>
    <tbody>
      <?php 

      $campanha = $_SESSION['campanha'];
      $query = sprintf("select int.start_time,int.nodename, int.dtmf,int.acao,cont.nome from ivr_interacao int , ivr_contatos cont where int.codigo = 798777 and cont.codigo = 798777");

    $result = Populator::ConsultaDB($query);

    $cont = 0;
    while ($resultado = pg_fetch_array($result) ) {
      $nome = $resultado['nome'];
      $acao = $resultado['acao'];
      $tempo = $resultado['start_time'];
      $cont = $cont + 1;
        echo '       
        ';
    }
     ?>

   <tr>
     <td><?php echo $nome; ?></td>
     <td></td>
  </tr>

Here is an example of the page like this: inserir a descrição da imagem aqui

  • Made an edit in the reply that contained syntax error that caused registry editing error.

1 answer

1

You can adapt this example to your needs.

<?php
//declaração das variaveis
$id = "";
$nome = "";
$tel = "";
$cel = "";
$email = "";

//conexão ao banco de dados
include_once('conectar.php');

if(!empty($_GET['acao'])){
   $acao = $_GET['acao'];

   if(($acao == "cadastrar")||($acao == "alterar")){
      $nome = $_POST['nome'];
      $tel = $_POST['tel'];
      $cel = $_POST['cel'];
      $email = $_POST['email'];

   }

   if($acao == "cadastrar"){
      $sql = ("insert into registro (nome, tel, cel, email) values ('$nome','$tel','$cel','$email')");
      $resultado = mysqli_query($conn,$sql);
   }else if($acao == "excluir"){
      $id = $_GET['id'];
      $sql = ("delete from registro where id = '$id'");
      $resultado = mysqli_query($conn,$sql);
   }else if($acao == "alterar"){ 
      $id = $_POST['id'];
      $sql = ("update registro set nome = '$nome',tel = '$tel',cel = '$cel',email = '$email' where id = '$id'");
      $resultado = mysqli_query($conn,$sql);
   }
}
?>

<!-- Biblioteca requerida -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<body>


<script>
/********************************************************************************
Função disparada ao clicar no link que abre o modal para edição (Modal Alterar)
valor e uma string com os dados cujo separador é um asteristico.
Com o metodo split separamos essa string para formar os valores a serem inseridos
nos campos do formulário do Modal Alterar
********************************************************************************/

function obterDadosModal(valor) {

   var retorno = valor.split("*");

   document.getElementById('id').value = retorno[0];   
   document.getElementById('nome').value = retorno[1];    
   document.getElementById('tel').value = retorno[2];
   document.getElementById('cel').value = retorno[3];  
   document.getElementById('email').value = retorno[4];  
}
</script>


<!--Modal Cadastrar-->
<div class="modal fade" id="myModalCadastrar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">

        <div class="modal-content">
            <div class="modal-header">
                <h1>Adicione uma pessoa para que possa ter o seu registro salvo</h1>
            </div>
            <div class="modal-body">
                <!--- Modal com form para se fazer inclusão de registro -->
                <form class="form-group well" action="modal-edicao-registro.php?acao=cadastrar" method="POST">
                        <input type="text" name="nome" class="span3" value="" required placeholder="Nome" style=" margin-bottom: -2px; height: 25px;"><br><br>
                        <input type="tel" name="tel" class="span3" placeholder="Número de telefone" required value="" style=" margin-bottom: -2px; height: 25px;">
                        <input type="tel" name="cel" class="span3 pull-right" placeholder="Número de celular" required value="" style=" margin-bottom: -2px; height: 25px;"><br><br>
                        <input type="text" name="email" class="span3" value="" required placeholder="Endereço email" style=" margin-bottom: -2px; height: 25px;"><br><br>
                        <button type="submit" class="btn btn-success btn-large" name="adicionar" style="height: 35px">Adicionar registro</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
            </div>
        </div>
    </div>
</div>


<!--Modal Alterar-->
<div class="modal fade" id="myModalAlterar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">

        <div class="modal-content">
            <div class="modal-header">
                <h1>Alteração de Registro</h1>
            </div>
            <div class="modal-body">
                <!--- Modal com form para se fazer a edição das informações -->
                <form class="form-group well" action="modal-edicao-registro.php?acao=alterar" method="POST">
                        ID <input id="id" type="text" name="id" value="">
                        Nome <input id="nome" type="text" name="nome" class="span3" value="" required style=" margin-bottom: -2px; height: 25px;"><br><br>
                        Tel  <input id="tel" type="tel" name="tel" class="span3" required value="" style=" margin-bottom: -2px; height: 25px;">
                        Cel <input id="cel" type="tel" name="cel" class="span3" required value="" style=" margin-bottom: -2px; height: 25px;"><br><br>
                        Email <input id="email" type="text" name="email" class="span3" value="" required style=" margin-bottom: -2px; height: 25px;"><br><br>
                        <button type="submit" class="btn btn-success btn-large" name="editar" style="height: 35px">Alterar registro</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
            </div>
        </div>
    </div>
</div>

<div class="container">
<div class="row">
<h2>Lista de pessoas registradas</h2><br>
    <form method="POST" action="modal-edicao-registro.php?acao=dados">
        <input type="text" name="pesquisa" placeholder="Pesquisar pessoas" class="span4" style="margin-bottom: -2px; height: 25px;">
        <button type="submit" name="pesquisar" class="btn btn-large" style="height: 35px;">Pesquisar</button> 
        <a href="#myModalCadastrar"><button type="button" name="cadastrar" class="btn btn-primary" data-toggle="modal" data-target="#myModalCadastrar">Cadastrar</button></a>
    </form>
    <table border="1px" bordercolor="gray" class="table table-stripped">
        <tr>
            <td>Nome</td>
            <td>Telefone Fixo</td>
            <td>Celular</td>
            <td>Email</td>
            <td>Ação</td>
        </tr>
            <?php

                $consulta = ("select * from registro");

                if(!empty($_POST['pesquisa']))
                {
                    $pesquisa = $_POST['pesquisa'];
                    $consulta = ("select * from registro where nome like '$pesquisa%'");
                }

                $result = mysqli_query($conn, $consulta);

                while($dados = mysqli_fetch_array($result)){
            ?>
        <tr>
            <td><?php echo $dados['nome']; ?></td>
            <td><?php echo $dados['tel']; ?></td>
            <td><?php echo $dados['cel']; ?></td>
            <td><?php echo $dados['email']; ?></td>
            <td>
                <a href="modal-edicao-registro.php?acao=excluir&id=<?php echo $dados['id'];?>" onclick="return confirm('Deseja realmente excluir este registro?');"><button class="btn btn-danger" type="button" name="excluir">Excluir</button></a>

                <a href="#myModalAlterar" onclick="obterDadosModal('<?php echo $dados['id'];?>*<?php echo $dados['nome'];?>*<?php echo $dados['tel'];?>*<?php echo $dados['cel'];?>*<?php echo $dados['email'];?>')"><button type='button' id='alterar' name='alterar' class='btn btn-primary' data-toggle='modal' data-target='#myModalAlterar'>Editar</button></a>

            </td>
        </tr>
            <?php
                }
                mysqli_close($conn);
            ?>
    </table>
</div>
</div>

On 09/07/2018 was made an edition in this line
<a href="#myModalAlterar" onclick="obterDadosModal('...$dados['email'];?><button...

lack of quotation mark and parenthesis ') closing function obterDadosModal and closing of tag a >.

Correct: <a href="#myModalAlterar" onclick="obterDadosModal('......$dados['email'];?>')"><button...

  • Oops, thank you, I’ll study the code, thank you!

  • Okay, don’t forget to validate the data, both on the front and back end. Any questions leave comment here!!!

Browser other questions tagged

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