Remove blob with ajax, button inside modal

0

I can not access all the data since it stays in the first iteration, that is, I can only access the first ID, this is necessary to be able to delete the correct blob file. The html part is huge because I show the information in a table first, and the iteration works, but not when it is in the modal windows.

.js

<script class="javascript">
    function EliminarDatos(id, url){
       var nombre = $id;
       var url = url;
       $.ajax({
           type:'POST',
           url: 'url',
           data:(nombre),
       });
    }
</script>

php

<?php 
  include "conexion.php";
  $rut=$_POST['id'];

  $query="DELETE CV FROM personalrrhh WHERE RUT='$rut'";
  mysqli_query($link,$query);
  header("Location: table_data_tables.php");

?>

HTML

       <div class="table-responsive">

                 <?php
                    //conexion
                    include "conexion.php";

                    //consulta bd
                    $query="SELECT * FROM personalrrhh";
                    $result=mysqli_query($link,$query);
                    $dato = mysqli_fetch_array($result);
                 ?> 


                <table class="table table-striped table-bordered table-hover dataTables-example" id="mitabla">
                <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Segundo nombre</th>
                    <th>Apellido</th>
                    <th>Segundo Apellido</th>
                    <th>Rut</th>
                    <th>Codigo trabajador</th>
                    <th>Fecha Nacimiento</th>
                    <th>Teléfono</th>                        
                    <th>Email</th>
                    <th>Email 2</th>
                    <th>Direccion</th>
                    <th>Ciudad</th>
                    <th>Comuna</th>
                    <th>Región</th>
                    <th>Direccion alternativa</th>
                    <th>Ciudad alternativa</th>                        
                    <th>Comuna alternativa</th>                        
                    <th>Región alternativa</th>
                    <th>Web</th>
                    <th>Contacto emergencia</th>
                    <th>Fono emergencia</th>
                    <th>Alergias</th>
                    <th>Grupo sangre</th>
                    <th>Valor HH</th>
                    <th>Sueldo base</th>
                    <th>Prevision Salud</th>
                    <th>Prevision Social</th>
                    <th>Documentos</th>
                    <th>Editar</th>

                </tr>
                </thead>
                <tbody>
                <?php
                    do{
                ?>

                <tr>
                    <td><p class="h6"><?php echo utf8_encode($dato['NOMBRE_1']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['NOMBRE_2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['APELLIDO_PAT']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['APELLIDO_MAT']);?></p></td>
                    <td><p class="h6"><?php echo $dato['RUN'];?></p></td>
                    <td><p class="h6"><?php echo $dato['COD_TRABAJADOR'];?></p></td>
                    <td><p class="h6"><?php echo $dato['FECHANACIMIENTO'];?></p></td>
                    <td><p class="h6"><?php echo $dato['FONO1'];?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['CORREO_ELECTRONICO']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['CORREO_ELECTRONICO2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['DIRECCION1']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['CIUDAD1']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['COMUNA1']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['REGION1']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['DIRECCION2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['CIUDAD2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['COMUNA2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['REGION2']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['WEB_PERSONAL']);?></p></td>
                    <td><p class="h6"><?php echo $dato['NAME_EMERGENCIA'];?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['FONO_EMERGENCIA']);?></p></td>
                    <td><p class="h6"><?php echo utf8_encode($dato['ALERGIAS']);?></p></td>
                    <td><p class="h6"><?php echo $dato['GRUPOSANGRE'];?></p></td>
                    <td><p class="h6"><?php echo $dato['VALOR_HH'];?></p></td>
                    <td><p class="h6"><?php echo $dato['SUELDO_BASE'];?></p></td>
                    <td><p class="h6"><?php echo $dato['prevision_salud_ID_PREVSALUD'];?></p></td>
                    <td><p class="h6"><?php echo $dato['prevision_social_ID_PREVSOCIAL'];?></p></td>
                    <td><br><p> </p><button href="#ventana1" class="btn btn-primary  dim" type="button" data-toggle="modal"><i class=" fa fa-file-pdf-o"></i></button></td>
                    <td><br><p> </p><button href="#ventana2" class="btn btn-primary  dim" type="button" data-toggle="modal"><i class=" fa fa-file-pdf-o"></i></button></td>
                    <!--Modal que contiene los docs-->
                    <div class="modal fade" id="ventana1">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <!--Header de la ventana-->
                                <div class="modal-header">
                                    <button tyle="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h2 class="modal-title">Documentos</h2>
                                </div>
                                <!--Contenido de la ventana-->
                                <div class="modal-body">

                                    <button type="button" class="btn btn-w-m btn-link" >Curriculum Vitae</button><b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>
                                    <button type="button" class="btn btn-primary btn-xs">Imprimir</button>
                                    <button type="button" class="btn btn-info btn-xs">Descargar</button>

                                    <button type="button" class="btn btn-default btn-xs" href="#ventana3" data-toggle="modal">Editar</button>
                                    <div class="modal fade" id="ventana3">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button tyle="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                    <h2 class="modal-title">Subir Documento</h2>                                                        
                                                </div>
                                                <div class="modal-body">
                                                    <form method="post" class="form-horizontal" enctype="multipart/form-data">
                                                    <div class="form-group">
                                                    <input type="file" class="form-control" name="cv" id="$id"></div>
                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-w-m btn-default" data-dismiss="modal">Cerrar</button>
                                                    <button type="submit" class="btn btn-w-m btn-primary" onclick="EditarDatos('<?php echo $dato['RUN'];?>','editar.php')">Guardar Cambios</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>                                   
                                    <button type="button" class="btn btn-danger btn-xs" data-toggle="modal" onclick="EliminarDatos('<?php echo $dato['RUN'];?>','deletecv.php')">Eliminar</button>
                                </div>
                                <!-- Footer ventana-->
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-w-m btn-default" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" class="btn btn-w-m btn-primary">Guardar Cambios</button>
                                </div>
                            </div>
                        </div>
                    </div>  
                </tr>
                <?php
                    }while ($dato = mysqli_fetch_array($result));
                ?>
                </tbody>
                </table>

    
asked by Camilo 17.01.2017 в 15:16
source

1 answer

0

You can check this link: link

They are doing it using POO but you can translate it to be style by procedures.

If you notice in the example they are just putting the whole result in an auxiliary array:

while($row = $mysqli_fetch_array($result))
{
   $rows[] = $row;
}

Then you can go through $ rows

foreach($rows as $row)
{
  echo $row['NOMBRE_1'];
}
    
answered by 19.01.2017 в 20:40