Get client id clicked and write to a variable to retrieve in a modal

-1

My PHP code has a while that lists the registered users, from a MYSQL query.

This list of users shows photo , id , name and a link to open a modal. Here is the while code:

<?php
  error_reporting(E_ALL ^ E_DEPRECATED);
  $link = mysql_connect("localhost","root","") or die ("Não foi possível conectar servidor");
  $banco = mysql_select_db('rscc-db', $link) or die ("Impossível conectar banco de dados");
  $sql = mysql_query("SELECT id,nome,foto FROM tb_usuarios order by nome");
  while ($dadosUsu = mysql_fetch_assoc($sql)) {
    $id_usu = $dadosUsu['id'];
    $nome_usu = $dadosUsu['nome'];
    $foto_usu = $dadosUsu['foto'];
    echo "<img src='fotos/".$foto_usu."' alt='Foto de exibição'; width='25'; height='30'; align='left'; /><br />";
    echo $id_usu;
    echo $nome_usu;
    echo '<a href="#pagina" class="pagina click"> Info</a><br />';
  }
?>  

If you click on the "Info" link of any of the listed users, the modal window opens. Here is the JavaScript tag and the Divs structure of the modal:

<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript">
    $(document).ready(function(e) {
        if($.cookie('modal') !== undefined){
            $('#modal').css('display','none');
        }
            $('.pagina').click(function(){
                 $('#modal').fadeIn(200);
            });
            $('.fechar, #modal').click(function(event){
                if(event.target !== this){
                    return;
                }
            $('#modal').fadeOut(200);
                $.cookie('modal', '1', { expires: 7 });
            });
        });
 </script>




<div id="modal">
    <div class="modal-box">
        <div class="modal-box-conteudo">

            <?php
                error_reporting(E_ALL ^ E_DEPRECATED);
                $link = mysql_connect("localhost","root","") or die ("Não foi possível conectar servidor");
                $banco = mysql_select_db('rscc-db', $link) or die ("Impossível conectar banco de dados");
                $sql = mysql_query("SELECT id,nome,email,foto FROM tb_usuarios where id='**$id_usuario**'");

---- continuação do código -----

              ?>
        </div>
       <div class="fechar">X</div>
   </div>
</div>

I would like to know how I could store the id of the user that was clicked to use in this query within the Modal.

    
asked by anonymous 25.10.2017 / 07:13

1 answer

0

You can put a date attribute or even id on your link by getting the variable id and get it by javascript and assign to some input field of your modal. Ex:

PHP

echo '<a href="#pagina" data-id="'.$id_usu.'" class="pagina click"> Info</a><br />';

Js

 $('.pagina').click(function(){
    # o $(this) é o objeto clicado, ou seja, o link e estou pegando o
    # conteúdo do campo data-id e atribuindo a um input dentro da sua modal
    $("#input-na-modal").val($($(this).attr("data-id"));

    $('#modal').fadeIn(200);
 });
    
25.10.2017 / 13:11