How do I pass data-id to a php variable?

-3

I have a table that I fill from a database in this table. I have a column with a column where, when I click on it, a table should appear in a modal form where data from that row's data is stored. The problem is that I do not know how pass the identifier of that row to consult my database, the identifier I keep in a data-id, thanks

code

 <?php  
  include_once('../application/variables_globales.php');

  include_once('../application/conexion.php');
  include_once('../models/tratamientoModel.php');
  include_once('../models/asistenciaModel.php');
  include_once('../models/visitaModel.php');

  $cod_centro =$_GET['cod_centro'];
  $tipo_usuario = $_SESSION['usuario']['cargous'];
  $nombre_usuario = $_SESSION['usuario']['nombre'];


  $pacientes_pares_visistas = lista_pacientes_pares_visitas($enlace, $cod_centro);

 // var_dump($pacientes_pares_visistas);
?>
<div class="col-md-8">
  <table class="table table-hover">
    <thead>
      <tr>
        <th>N° DE ORDEN</th>
        <th>DNI </th>
        <th>CASO</th>
        <th>PACIENTE</th>
        <th>NUMERO DE VISITAS</th>       
      </tr>
    </thead>
    <tbody>
    <?php  
     $i=1;
      foreach ($pacientes_pares_visistas  as $fila) 
        {
           ?>
              <tr>
                <td align="center"><?php echo $i++; ?></td>
                <td align="center"><?php echo $fila['dni']; ?></td>
                <td align="center"><?php echo $fila['nro_caso']; ?></td>   
                <td align="center"><?php echo $fila['nombre']." ".$fila['apellido_paterno']." ".$fila['apellido_materno']; ?></td>
                <td align="center"><a href="#" data-id="<?php echo $fila['dni']; ?>" data-toggle="modal" data-target="#myModalVisita" ><?php echo $fila['cntidad_visitas']; ?></a></td>
                <td align="center"></td>                   
              </tr>
            <?php
         }         
    ?>    
    </tbody>
  </table>
</div>
<div id="myModalVisita" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title text-center">VISITAS PROGRAMADAS</h4>
      </div>
      <div class="modal-body">

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  $(document).ready(function (e) {
    $('[data-toggle="tooltip"]').tooltip();
    $('#myModalVisita').on('show.bs.modal', function(e) {    

    });
  });
</script>
    
asked by ingswsm 09.10.2017 в 20:15
source

1 answer

0

1) Add a class in the hyperlink that triggers the Modal. for example class="miClass"

2) By JQuery we capture the click in .miClass and assign the value of the data-id to the element that we want inside the Body of the Modal. (add ID to the element where the information will be displayed).

id="idData"

Using JQuery we would do something like the following:

 $(document).on("click", ".miClass, function () {
        var data = $(this).data('id');
        $(".modal-body #idData").val( data );
 });
    
answered by 12.10.2017 в 05:04